473,765 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Web.Mail embedding images?

Hi, I hope there is someone reading this that has the answer, Please Help!

I have the need to send a html email via asp.net. its easy enough to send
an html email and add attachments.
My question is, how to you set the Content-Location of each attachment in
the mail headers so that the images are embedded in the html email rather
than attached?

This is my code:

private void Page_Load(objec t sender, System.EventArg s e)
{

MailMessage objEmail = new MailMessage();

objEmail.From = as****@domain.c om;
objEmail.Subjec t = "news flash ";
string body = "<html>.... .
{some html code with images as <img src=\"news_r1_c 1.jpg\"> ... etc
</html>";
objEmail.Body = body;
objEmail.Priori ty = MailPriority.No rmal;
objEmail.BodyFo rmat = MailFormat.Html ;

MailAttachment i1 = new
MailAttachment( Server.MapPath( "images/news_r1_c1.jpg" ));
MailAttachment i2 = new
MailAttachment( Server.MapPath( "images/news_r1_c3.gif" ));
MailAttachment i3 = new
MailAttachment( Server.MapPath( "images/spacer.gif"));
MailAttachment i4 = new
MailAttachment( Server.MapPath( "images/news_r4_c1.jpg" ));
MailAttachment picture = new
MailAttachment( Server.MapPath( "images/default.jpg"));

objEmail.Attach ments.Add(i1);
objEmail.Attach ments.Add(i2);
objEmail.Attach ments.Add(i3);
objEmail.Attach ments.Add(i4);
objEmail.Attach ments.Add(pictu re);

string sendto = Request.Form["recipients "];
string[] recipients= sendto.Split(', ',';');
foreach(string recipient in recipients)
{
objEmail.To = recipient.Trim( );
SmtpMail.SmtpSe rver = "smtp.server,co m";

try
{
SmtpMail.Send(o bjEmail);
}
catch (Exception exc)
{
Response.Write( "Send failure: " + exc.ToString()) ;
}
}
}

as said, html email is coming through fine, images are in email as
Attachments, but DON'T display inline with the page (even though the
attachments are named correctly corresponding to the image names in the HTML
(<img src="imagename. jpg"> where imagename.jpg is attached).

I have sent HTML emails with embedded images in Classic ASP using CDONTS
quite easily, i need to do the same in .NET!
[FYI code to attach in ASP is:
objMail.AttachU RL server.MapPath( "images/imagename.jpg") , "imagename. jpg"
]

a quick look at the message source shows this at the top of the part that
holds the binary information about the image, in the email source:

for the ASP version (that works) :

------=_NextPart_000_ 000A_01C3EF89.6 2C8CA30
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Disposition: attachment
Content-Location: news_r1_c1.jpg

in the ASP.NET version (doesn't show images inline)

------=_NextPart_000_ 005D_01C3F184.E CF34990
Content-Type: image/jpeg;
name="news_r1_c 1.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="news_ r1_c1.jpg"

notice how there is no Content-Location with the image name in the .NET
version, this is obviously needed to tell the mail client where the attached
images should be displayed in the HTML email.

Now does anyone know how to set this in the .NET mail object??
any help/leads in the right direction are appreciated.
The doesn't seem to be anywhere to set this property in the MailAttachment,
or MailAttachments .Add methods, and i couldn't find any answers in the docs

Please help

Thanks
Tim

PS. (although i'm using c#, vb code will do if you code in VB.NET)

Nov 18 '05 #1
3 5687
"Tim T" <br*********@ho tmail.com> wrote in
news:ed******** ******@tk2msftn gp13.phx.gbl:
I have the need to send a html email via asp.net. its easy enough to
send an html email and add attachments.
My question is, how to you set the Content-Location of each attachment
in the mail headers so that the images are embedded in the html email
rather than attached?
System.WebMail does not support alternative types which is the proper way to
send HTML. If you send as attachments not all mail clients will read it, and
many spam filters will kill your mail.

Indy supports HTML mail thoguh, and its free.

http://www.indyproject.org/
string body = "<html>.... .
{some html code with images as <img src=\"news_r1_c 1.jpg\"> ... etc
You didnt send this right. You are just stuffing HTML into a text body. This
will trigger spam filters like crazy, and very few mail clients will display
it.

You have to send a properly formatted multi part altnernative message.
MailAttachment i1 = new
MailAttachment( Server.MapPath( "images/news_r1_c1.jpg" ));
You dont send them as attachments. You send them as message parts instead
with Content ID headers.
as said, html email is coming through fine, images are in email as
Attachments, but DON'T display inline with the page (even though the
attachments are named correctly corresponding to the image names in the
HTML (<img src="imagename. jpg"> where imagename.jpg is attached).


Thats becauase you are not formatting the mail according to standards.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com

Nov 18 '05 #2
Thanks for that Chad, now it certainly helped in my understanding on how to
send html emails properly.
I had a look at Indy, and couldn't find anything on sending email using .NET
do you know of any example c# code to do what i need to do properly?
I downloaded this .NET component that does it propertly:
http://www.waldorf.uklinux.net/index.php
just wondering if anyone knows if there is any good source code examples out
there to do this??

Thanks again

Tim

"Chad Z. Hower aka Kudzu" <cp**@hower.org > wrote in message
news:Xn******** **********@127. 0.0.1...
"Tim T" <br*********@ho tmail.com> wrote in
news:ed******** ******@tk2msftn gp13.phx.gbl:
I have the need to send a html email via asp.net. its easy enough to
send an html email and add attachments.
My question is, how to you set the Content-Location of each attachment
in the mail headers so that the images are embedded in the html email
rather than attached?
System.WebMail does not support alternative types which is the proper way

to send HTML. If you send as attachments not all mail clients will read it, and many spam filters will kill your mail.

Indy supports HTML mail thoguh, and its free.

http://www.indyproject.org/
string body = "<html>.... .
{some html code with images as <img src=\"news_r1_c 1.jpg\"> ... etc
You didnt send this right. You are just stuffing HTML into a text body.

This will trigger spam filters like crazy, and very few mail clients will display it.

You have to send a properly formatted multi part altnernative message.
MailAttachment i1 = new
MailAttachment( Server.MapPath( "images/news_r1_c1.jpg" ));


You dont send them as attachments. You send them as message parts instead
with Content ID headers.
as said, html email is coming through fine, images are in email as
Attachments, but DON'T display inline with the page (even though the
attachments are named correctly corresponding to the image names in the
HTML (<img src="imagename. jpg"> where imagename.jpg is attached).


Thats becauase you are not formatting the mail according to standards.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com

Nov 18 '05 #3
"Tim T" <br*********@ho tmail.com> wrote in
news:ur******** ******@TK2MSFTN GP10.phx.gbl:
Thanks for that Chad, now it certainly helped in my understanding on how
to send html emails properly.
Your welcome.
I had a look at Indy, and couldn't find anything on sending email using
.NET do you know of any example c# code to do what i need to do
http://www.atozed.com/indy then click demos.

Its just plain text, but google will turn up a bunch of Delphi code that
shows you how to do the HTML parts.
properly? I downloaded this .NET component that does it propertly:
http://www.waldorf.uklinux.net/index.php


If it works for you.. but it looks a bit limited even by its own admissions.
Im also not sure that its doing the HTML mails properly. If its not, you are
going to get filtered a LOT by spam tools.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1738
by: prasanna | last post by:
Hello I tried to send mail from PHP in html format. But an ! mark appears in mail body in Inbox. I tried to print body text on page before sending mail and it does not show ! mark. I replaced ! mark from mail body before passing it to mail() function but then also it adds ! mark in mail body. Can you please tell me why this is happening? Thanks
2
8277
by: Dean J. Garrett | last post by:
Hi, I need to create HTML e-mail from an ASP program that includes embedded images that go along with the e-mail, e.g. logos, product image, etc. Is there a technique in HTML that people use to embed images? I know that when I insert an image into an e-mail in Outlook, and I look at the HTML behind it, there is a funny tak CID: IMG hspace=0 src="cid:027301c29d8e$da6ba600$0afea8c0@MYMAIN" align=baseline border=0>
1
503
by: Will Pittenger | last post by:
I have a program where I used Win32 calls to add items to my form's system menu. Now I am attempting to have those items use the same icon that the corresponding toolbar button uses. I thought that I could just access the image on the fly and send it to Windows. Trouble is that results in an image with dark blue where the image is transparent. (The menu's background is the standard BTNFACE color.) My code is below. All need is a...
2
1154
by: Ersin Gençtürk | last post by:
is it possible to embedd images as inline images into e-mail in pure asp.net ? I don't want my pictures sent like attachment , but I want to send them as inline pictures.Is there any way to do this ? or freeware some code ? compoenent ? etc.
3
1543
by: Ersin Gençtürk | last post by:
hi, which component do you prefer to send emails with embedded images ? Is there a freeware and native .net component available ? Note that I don't want to send images as attachments.
6
22807
by: Edward | last post by:
I have been doing some research about embedding images in HTML using the data URL src method of the format: <img src="/-/data:image/gif;base64,<DATA>"> My question is, how does one generate this <DATA> string? I have found some on the web that I can load into my browser but if I save this image and then view in Notepad it looks much different than the string that I used in <DATA> and is full of non-alphanumeric symbols. Also, I have...
1
5194
by: MissMarie | last post by:
I've been playing around with DIV tables in myspace to better learn how to rewrite my own code for my business site without having to pay someone to design it. I've tried embedding a slideshow into a div table and after I save it I noticed that the slideshow does not show up and the embed code I added is altered. Can anyone help me figure this out? The embed code that I'm talking about is three quarters down the code page under {PHOTOS},...
0
38010
digicrowd
by: digicrowd | last post by:
http://bytes.com/images/howtos/applemail_sig_icon.jpg At first glance, it may not appear that Apple Mail (otherwise known as Mail.app) supports the use of HTML signature emails. However, with a little terminal and Safari magic, you will be sending HTML signatures. 1. Prepare your HTML signature. Open TextEdit or your favorite HTML editor and create your signature just how you want it to look. Remember to keep it simple as most mail...
0
9393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9946
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.