Sponsored by
www.aspnetemail.com
|
 |
Discuss This FAQ Item
Got a question? Another Suggestion? Want to post your solution? Discuss it below.
-
Embed images in Email
[ Reply ]
I have done this so that an email is sent from a web site and an image from the website is embedded in the actual email (still shows as attachment obviously)
... msg.BodyFormat = MailFormat.Html; msg.Body = "<IMG SRC=\"cmsm1_multi.gif\">"; //only name of image file msg.Body += "Any other stuff for body"; ... MailAttachment imgObj = new MailAttachment(Server.MapPath("/") + "web/images/cmsm1_multi.gif"); //actual location of image file msg.Attachments.Add(imgObj); ... //send the message
Dave [ landerd ( at ) qnp dot newsltd dot com dot au ],
2004-03-16 16:26:37
#
-
RE: Embed images in Email
[ Reply ]
yeah, but send yourself the email, but don't look at it. Make sure it is downloaded to your client (outlook or outlook express).
Disconnect from the internet. While in offline mode, you will the image is broken. Sure the image is attached, but it's not embedded. Embedded images are where you can view the images, while in offline mode. No additional requests are made to the webserver.
You have to make sure you don't first view the image, because some clients will download the image and cache it.
hth, Dave
Dave Wanta [ dave ( at ) 123aspx dot com ],
2004-03-16 18:10:43
#
-
RE: Embed images in Email
[ Reply ]
By this way, the image is not embedded in the mail body but, it still goes with the mail as an attachment. So the recipient will be able to see the image in offline mode. This is the best way to send mails including images with System.Web.Mail if you are not using a third party product.
CeCHeN [ tezcan ( at ) docuart dot com ],
2004-12-02 07:01:40
#
-
RE RE: Embed images in Email
[ Reply ]
try this Mail.Body="<HTML><BODY BACKGROUND=""cid:My-Image"">...</HTML>" Mail.AddEmbeddedImage "c:\aspemaildir\margin.gif", "My-Image"
Rupan [ rupangupta ( at ) gmail dot com ],
2006-06-01 07:29:30
#
-
RE: RE RE: Embed images in Email
[ Reply ]
That isn't any method on the MailMessage class, either in 1.1 or 2.0. What library are you using?
Marc [ madacram ( at ) yahoo dot com ],
2007-03-16 10:14:51
#
-
RE: Embed images in Email
[ Reply ]
Even though images do show up in Outlook Express, they won't for Gmail. Anyway, thanks! It is better than none.
Zou Yu [ No1 dot Mail ( at ) gmail dot com ],
2006-01-27 07:48:53
#
-
RE: Embed images in Email
[ Reply ]
Hi All, Use CDOSYS to embed images in the mail. User CreateHTML method.
Search google for CDOSYS C#. CDOSYS is designed and developed from scratch. .NET uses CDOSYS.
Regards, (Varinder Hatta)
Varinder Hatta [ vhatta ( at ) pugmarks dot com ],
2006-07-17 01:07:42
#
-
RE: Embed images in Email
[ Reply ]
you cant embed images in an email
joe [ joe ( at ) aol dot com ],
2006-08-21 09:45:15
#
-
RE RE: Embed images in Email
[ Reply ]
Riiiight. What about all those Image SPAMs I get that don't actually download an image, but the image is actually in the header??
anonymous-coward [ test ( at ) test dot com ],
2007-07-03 15:05:33
#
-
RE: RE RE: Embed images in Email
[ Reply ]
I do it by creating the page with ms frontpage , then opening the file in IE... from IE select file, send by email... note that the images will need to be on a public internet server...
JDuke [ duque_jo ( at ) hotmail dot com ],
2008-01-29 17:00:01
#
-
RE RE: Embed images in Email
[ Reply ]
You can embed images in an email but I don't know how.
eyes [ fwenvajfdlkaf ( at ) yahoo dot com ],
2009-08-07 19:32:01
#
-
RE: Embed images in Email
[ Reply ]
ok
Masabo [ kmasabo ( at ) yahoo dot com ],
2006-09-25 06:53:52
#
-
RE: Embed images in Email
[ Reply ]
I think that it its possible, when use atachment properyy together with html coding, can send embed images
Luis Contreras [ luiscontrerasf ( at ) prodigy dot net dot mx ],
2009-02-26 10:43:43
#
-
embedding images
[ Reply ]
where can I find an example or at least some hints about embedding images in an email?
razvan [ razdanro ( at ) yahoo dot com ],
2004-09-06 07:10:55
#
-
RE: embedding images
[ Reply ]
I'm assuming you read the above faq, so you need a 3rd party component.
Check out my component: aspNetEmail http://www.aspnetemail.com/help/welcome/sample_multipartembeddingimage.html
Cheers! Dave
Dave Wanta [ dave ( at ) 123aspx dot com ],
2004-09-06 07:15:49
#
-
RE RE: embedding images
[ Reply ]
So if it can't be done, how do the third party companies do it?
Bill [ notpublished ( at ) nothing dot com ],
2004-09-13 13:41:06
#
-
RE: RE RE: embedding images
[ Reply ]
well, in my case (and I'm sure the others), I wrote it from the ground up. aspNetEmail does not depend upon System.Web.Mail. Thus, I control what options I want to give the end developer for formatting their email message.
Cheers! Dave
dave wanta [ dave ( at ) 123aspx dot com ],
2004-09-13 13:43:36
#
-
RE RE: RE RE: embedding images
[ Reply ]
Can you please explain ground up method, any idea how to achieve image embeding in mail message...
Aatif [ aatif_malik ( at ) hotmail dot com ],
2004-10-05 00:48:35
#
-
RE: RE RE: RE RE: embedding images
[ Reply ]
Explain 'Ground Up'? Are you kidding. How about "start from scratch".
Brandon [ bcissell ( at ) thedailyread dot com ],
2004-12-01 06:58:45
#
-
RE RE: RE RE: RE RE: embedding images
[ Reply ]
----Explain 'Ground Up'? Are you kidding. How about "start from scratch". -----
Why not? Dont want to reveal your secrets?? Just give him a head start.
Craig
Craig [ craigcsb ( at ) hotmail dot com ],
2005-03-15 15:06:55
#
-
RE: RE RE: RE RE: RE RE: embedding images
[ Reply ]
Download the try version of aspNetEmail and than use reflector by Lutz Roeder. If this guy is not willing to give you a head start.
roel [ roel ( at ) ikke dot nl ],
2005-05-11 01:04:05
#
-
RE: RE RE: RE RE: RE RE: embedding images
[ Reply ]
Don't take it the wrong way, but be grateful for all free instruction and help Dave's already providing through this site.
Dave's has a commercial product that fills a market need that System.Web.Mail doesn't address. If I'd gone through the effort to create, market, sell, and support a commercial product to meet such a need, and someone said "can't you just tell me how to create your product?", I'd politely decline the offer as well.
Dan Kahler [ dan dot kahler ( at ) gmail dot com ],
2006-01-13 11:00:28
#
-
RE: RE RE: RE RE: RE RE: embedding images
[ Reply ]
How do I embed images in my Yahoo email?
Andy [ alfazulu7 ( at ) yahoo dot com ],
2006-05-10 07:08:47
#
-
RE: embedding images
[ Reply ]
How do I send an e-mail with an image in it, ie not as an attachment ??
Rob [ xesionprince ( at ) fsmail dot net ],
2005-05-25 04:20:41
#
-
RE RE: embedding images
[ Reply ]
Uuuh, maybe because it could take weeks?
Jon [ jon ( at ) basicillsion dot com ],
2005-06-01 17:52:33
#
-
RE RE: embedding images
[ Reply ]
'Send email message with free jmail, download it here: http://www.dimac.net/FreeDownloads/dlstart.asp?ProductID=5 ' Install in System32 and then register with "cmd /k regsvr32 c:\windows\system32\jmail.dll" ' Add as a reference JMail 4.0 library from COM tab
Dim jm As New jmail.Message
jm.Subject = "HTML with embedded image" jm.From = "a@b.ca" jm.FromName = "Fe La" jm.AddRecipient("fela@yahoo.ca") jm.Body = "A nice picture if you can read HTML-mail."
' The return value of AddAttachment is used as a ' reference to the image in the HTMLBody. Dim contentId As String contentId = jm.AddAttachment(System.AppDomain.CurrentDomain.BaseDirectory() & "cover.jpg", True, "image/jpeg")
Dim strContents As String strContents = "<html><body><font color=""red"">Hi, here is a nice picture:</font><br><img src=""cid:" & contentId & """><br><br>good one huh?</body></html>" jm.HTMLBody = strContents
' But as not all mailreaders are capable of showing HTML emails ' we will also add a standard text body jm.Body = "Too bad you can't read HTML-mail." jm.AppendText(" There would have been a nice picture for you")
jm.Logging = True jm.Silent = True If Not jm.Send("fela:my_password@smtp.mail.yahoo.ca") Then Console.WriteLine(" - Problem with sending email. JMail ErrorCode: " & jm.ErrorCode) End If
'End of Send email message
Gennady [ gkucheruk ( at ) yahoo dot ca ],
2005-06-02 13:36:54
#
-
RE: RE RE: embedding images
[ Reply ]
if you want to use a COM object it's too easy add a reference to CDOSYS.dll. Look at ..\system32 folder of your OS. Why download third parts COM objects?
ps: sorry for the language, i'm italian :-)
Gio [ mandalaqui ( at ) hotmail dot com ],
2005-06-17 09:41:00
#
-
RE: RE RE: embedding images
[ Reply ]
isn't there a way using html? I'm not a programmer... but looking at the source of other imaged emails I receive it looks possible?
andy [ andyodandy ( at ) gmail dot com ],
2008-09-16 16:25:17
#
-
RE: embedding images
[ Reply ]
'Send email message with free jmail, download it here: http://www.dimac.net/FreeDownloads/dlstart.asp?ProductID=5 ' Install in System32 and then register with "cmd /k regsvr32 c:\windows\system32\jmail.dll" ' Add as a reference JMail 4.0 library from COM tab
Dim jm As New jmail.Message
jm.Subject = "HTML with embedded image" jm.From = "a@b.ca" jm.FromName = "Fe La" jm.AddRecipient("fela@yahoo.ca") jm.Body = "A nice picture if you can read HTML-mail."
' The return value of AddAttachment is used as a ' reference to the image in the HTMLBody. Dim contentId As String contentId = jm.AddAttachment(System.AppDomain.CurrentDomain.BaseDirectory() & "cover.jpg", True, "image/jpeg")
Dim strContents As String strContents = "<html><body><font color=""red"">Hi, here is a nice picture:</font><br><img src=""cid:" & contentId & """><br><br>good one huh?</body></html>" jm.HTMLBody = strContents
' But as not all mailreaders are capable of showing HTML emails ' we will also add a standard text body jm.Body = "Too bad you can't read HTML-mail." jm.AppendText(" There would have been a nice picture for you")
jm.Logging = True jm.Silent = True If Not jm.Send("fela:my_password@smtp.mail.yahoo.ca") Then Console.WriteLine(" - Problem with sending email. JMail ErrorCode: " & jm.ErrorCode) End If
'End of Send email message
Gennady [ gennady ( at ) geriatricsandaging dot ca ],
2005-06-02 13:50:24
#
-
It IS possible, Just Use an RTF encoded email
[ Reply ]
Clearly you can create mime bodies with system.web.mail (although it isn't obvious) and if you render a message (including pictures) in rtf and then make rtf the message body, the images go along for the ride.
so it IS possible. Would love to see an example of someone who has send an RTF body message (NOT AN ATTACHMENT, but as the actual body)
good hunting
Jeff Gallino [ not ( at ) gonnahappen dot com ],
2005-08-02 07:15:31
#
-
RE: It IS possible, Just Use an RTF encoded email
[ Reply ]
So does anyone have a simple example of how to do this? I'm on a Mac. I have a very simple html doc with 1 image in it. Are there any tools to take my html and convert it to a sendable email format?
Any help is greatly appreciated, I'm on a deadline. Thanks, rich!
Richard Rabassa [ rabassa ( at ) lgaadv dot com ],
2005-09-13 05:59:36
#
-
RE RE: It IS possible, Just Use an RTF encoded email
[ Reply ]
Create your htm doc Open Outlook Express (as far as I know it can't be done in Outlook) , create a new mail Go to tools and "insert text from file" Select your html doc When the html loads up right click on the image, or where the image should be, and select properties. browse to Select the image from your hard drive Repeat for all images. Send the baby off :)
Michael [ it6 ( at ) tomatotechnologies dot com dot au ],
2005-11-20 21:06:04
#
-
How to embed images in RTF file
[ Reply ]
I m Creating a RTF file, by Transforming XML with a XSL file. In RTF file i m creating table and in table i have to add JPEG file at RUN time. XML file have path of JPEG file and other inforation.
Sudhanshu Bhatnagar [ sudhanshu_31 ( at ) yahoo dot com ],
2005-09-23 02:35:03
#
-
RE: How to embed images in RTF file
[ Reply ]
How do i embed a RTF file into an email. My file format is in rtf and i need to embed it into the email body
omlac [ kmakuwaza ( at ) yahoo dot com ],
2008-05-26 03:15:42
#
-
C# . NET
[ Reply ]
I am using C# .NET
I have got a table like structre where I am having some read only text boxes and labels where the data is populated based on some checks. I want to send the details in the same look to a mail account. Is it possible or I have to go for some work around.
Please suggest me how to do it .
Thanking in Advance.
sandeep [ sandeep_km2000 ( at ) rediffmail dot com ],
2005-10-04 06:13:31
#
-
embedding images in hotmail
[ Reply ]
is it at all possible to embed a photo or and image into a hotmail message
Jessie [ jessie551 ( at ) msn dot com ],
2005-12-07 01:24:16
#
-
RE: embedding images in hotmail
[ Reply ]
i know it is! i did it!! but i copied an email with embedded picturers on it and sent it to me. i cant get it to send me own though
carl [ not_tellin ( at ) hotmail dot com ],
2006-02-20 16:52:12
#
-
The way I do it
[ Reply ]
I have found the best way of doing this is to avoid using the .net framework, and use COM cdosys.dll
string email = "somebody@somewhere.com";
CDO.Message mm = new CDO.MessageClass(); mm.To = email; mm.From = "someoneelse@somewhere.com"; mm.Subject = "Test Email";
mm.HTMLBody = "Picture 1: <img src='image001.jpg'; mm.AddRelatedBodyPart(@"C:\share\image001.jpg","image001.jpg", CDO.CdoReferenceType.cdoRefTypeLocation, null, null);
CDO.Configuration objConfig = new CDO.ConfigurationClass();
objConfig.Fields["cdoSendUsingMethod"].Value = CDO.CdoSendUsing.cdoSendUsingPort;
objConfig.Fields["cdoSMTPServer"].Value = "MYSMTPSERVER" ;
objConfig.Fields["cdoSMTPServerPort"].Value = 25 ;
objConfig.Fields["cdoSMTPAuthenticate"].Value = CDO.CdoProtocolsAuthentication.cdoBasic;
objConfig.Fields.Update();
mm.Configuration = objConfig;
mm.Send();
Alex Wight [ alex ( at ) thewightstuff dot net ],
2006-03-15 04:06:53
#
-
Nope, here's the way to do it
[ Reply ]
Just a small and buggy function that I wrote. I'll embedd images just like Outlook does, using a cid.
public static MailMessage AttachImages(MailMessage message) { if (!message.IsBodyHtml) throw new ApplicationException("Message formart needs to be HTML");
Regex reg = new Regex("src[^>]*[^/].(?:jpg|bmp|gif)(?:\"|\')");
MailMessage messageOut = message;
foreach (Match match in reg.Matches(message.Body)) { string cid = Guid.NewGuid().ToString("N"); Stream srcStream; string src = match.Value; src = src.Replace("src=", ""); src = src.Replace("\"", "");
if (src.StartsWith("http://")) { WebRequest request = HttpWebRequest.Create(src); srcStream = request.GetResponse().GetResponseStream(); } else { srcStream = new MemoryStream(File.ReadAllBytes(src)); } Attachment newAttachment = new Attachment(srcStream, "image/" + Path.GetExtension(src).ToLower().Replace(".", "")); newAttachment.ContentId = cid; messageOut.Attachments.Add(newAttachment);
messageOut.Body = messageOut.Body.Replace(src, "cid:" + cid); }
return messageOut; }
Guilherme Magalhaes [ guilherme ( at ) iwire dot com dot br ],
2006-08-07 12:41:59
#
-
RE: Nope, here's the way to do it
[ Reply ]
Not only is this a 2.0 solution (uses System.Net.Mail), you'd probably be better off using LinkedResource rather than Attachment objects.
Marc [ madacram ( at ) yahoo dot com ],
2007-03-16 10:06:30
#
-
C# swap html img elements with embedded images
[ Reply ]
Uses MILHTMLParser.dll to parse the HTML downloaded from -http://www.codeproject.com/dotnet/apmilhtml.asp
Uses cdosys.dll in system32 for email functionality. Great help from posting at - http://support.jodohost.com/showthread.php?t=7692
public void ConvertImagesToEmbeddedMailImages(string html, ref CDO.Message emailMessage) { HtmlDocument document = HtmlDocument.Create(html, false); HtmlNodeCollection imageNodes = new HtmlNodeCollection(); // Get All the img nodes GetImageNodes(document.Nodes, ref imageNodes); foreach (HtmlElement element in imageNodes) { string path = HttpContext.Current.Server.MapPath(element.Attributes["src"].Value); FileInfo imageFileInfo = new FileInfo(HttpContext.Current.Server.MapPath(element.Attributes["src"].Value)); string contentId = imageFileInfo.Name.Replace(imageFileInfo.Extension, string.Empty); CDO.IBodyPart bodyPart = emailMessage.AddRelatedBodyPart(path, contentId, CDO.CdoReferenceType.cdoRefTypeLocation, string.Empty, string.Empty); bodyPart.Fields.Append("urn:schemas:mailheader:Content-ID", DataTypeEnum.adVariant, 255, FieldAttributeEnum.adFldMayBeNull, string.Format("<{0}>", contentId)); bodyPart.Fields.Update(); //Change the src to "cid:<contentId>" element.Attributes["src"].Value = string.Format("cid:{0}", contentId); } // set the email text to the modified html emailMessage.HTMLBody = document.HTML; }
private void GetImageNodes(HtmlNodeCollection nodes, ref HtmlNodeCollection imageNodes) { foreach (HtmlNode node in nodes) { HtmlElement element = node as HtmlElement; if (element != null) { if (element.Name.ToLower() == "img") { imageNodes.Add(element); } if (element.Nodes.Count > 0) { GetImageNodes(element.Nodes, ref imageNodes); } } } }
John Brathwaite [ john dot brathwaite ( at ) apnim dot co dot nz ],
2006-08-09 21:46:24
#
-
How to embed an image in e-mail with Asp.NET 2.0
[ Reply ]
1. Add your images as attachments to the e-mail message (MailMessage.Attachments).
2. Set the ContentId property to some unique value for each attached image you want to reference in the e-mail body.
3. Refer to the attached images in the body (HTML) using the unique ContentId in the following format: <img src="cid:ContentID"/>
4. Send the message and it should work.
Isaac Eckert [ iaegx6 ( at ) umr dot edu ],
2006-10-27 08:18:19
#
-
embedding an image
[ Reply ]
I was able to embed an image using the above suggestions....But now i have one more problem...
The image i am getting is from a referrer's page...and that image is dependent on what was selected...so my image is somewhat not fix...so how will i get the exact image that is being shown/ displayed from the referring page...becuase right now, what was embedded is a fix image...example: "<img src='http://www.mysite.com/images/myImage1.gif'/>"
What i need to show is if teh image being displayed in the referreing page is myImage2052.gif...then i need to show it...not myImage1.gif...
The images can be more than a million images...so how can i get teh right and exact image and embed it properly in my email?
Byock [ byockbrain ( at ) yahoo dot com ],
2006-11-23 18:32:37
#
-
RE: embedding an image
[ Reply ]
Add a LinkedResource to your MailMessage object.
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString("<html><body><p>prova</p><img src=""cid:IMG1"" alt="""" /></body></html>", Encoding.UTF8, "text/html")
' Inline Attachment IMG1
Dim img1 As New LinkedResource(HttpContext.Current.Server.MapPath("images/image.gif"))
img1.ContentId = "IMG1" img1.ContentType = New ContentType("image/jpeg") htmlView.LinkedResources.Add(img1)
msg.AlternateViews.Add(htmlView)
lotstyl [ sinzone ( at ) hotmail dot com ],
2007-07-23 11:02:32
#
|