Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

2.0 Mail attachment - Content-Type: multipart/related

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Will - 07 Jul 2005 14:28 GMT
The new System.Net.Mail.MailMessage is awesome.... but ...

I can't seem to find a way to send an html email with an image attachment,
and group them together with Content-Type: multipart/related. The code I
have works great for including the HTML images in the email. However, in
Outlook Express it will automatically insert the image at the end of the
email.. so all images show up twice. This doesn't happen if I could nest the
HTML and image inside of a multipart/related boundary.

Here's the code:

using(MailMessage message = new MailMessage())
{
message.Subject = Subject_TextBox.Text;
message.Body =
@"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<title>My Email</title>
</head>
<body>
<img src='cid:image1.jpg' />
</body>
</html>";
message.IsBodyHtml = true;
message.From = new MailAddress("webmaster@mydomain.net", "Webmaster");
message.To.Add(new MailAddress("me@mydomain.net"));
message.Attachments.Add(new Attachment(@"c:\image1.jpg"));
message.Attachments[0].ContentId = "image1.jpg";
message.Attachments[0].ContentDisposition.Inline = true;
message.Attachments[0].ContentDisposition.FileName = "image1.jpg";

SmtpClient mailClient = new SmtpClient();
mailClient.Send(message);
}
..
..
..
..
Here is what the message looks like: (without headers)

----boundary_6_bbca7c7e-266e-425a-bb11-62ad5d412982
content-type: text/html; charset=us-ascii
content-transfer-encoding: quoted-printable

<html>...
...</html>
----boundary_6_bbca7c7e-266e-425a-bb11-62ad5d412982
content-type: image/jpeg; name=image1.jpg
content-transfer-encoding: base64
content-id: <image1.jpg>
content-disposition: inline; filename=image1.jpg

/9j/4AAQSkZJRgABAQEAYABgAAD/4QAWRXhpZgAASUkqAAgAAAAAAAAAAAD/2wBDAAgGBgcG
...
TCM81IcYpntTAjbqKKcaKdguz//Z
----boundary_6_bbca7c7e-266e-425a-bb11-62ad5d412982--

..
..
..
..
..

Here is what I'd like it to look like: (without headers)

----boundary_7_035ffa64-2aaf-4135-9f4f-9b36d877cdc4
Content-Type: multipart/related;
boundary="----boundary_6_bbca7c7e-266e-425a-bb11-62ad5d412982"

----boundary_6_bbca7c7e-266e-425a-bb11-62ad5d412982
content-type: text/html; charset=us-ascii
content-transfer-encoding: quoted-printable

<html>...
...</html>
----boundary_6_bbca7c7e-266e-425a-bb11-62ad5d412982
content-type: image/jpeg; name=image1.jpg
content-transfer-encoding: base64
content-id: <image1.jpg>
content-disposition: inline; filename=image1.jpg

/9j/4AAQSkZJRgABAQEAYABgAAD/4QAWRXhpZgAASUkqAAgAAAAAAAAAAAD/2wBDAAgGBgcG
...
TCM81IcYpntTAjbqKKcaKdguz//Z
----boundary_6_bbca7c7e-266e-425a-bb11-62ad5d412982--

----boundary_7_035ffa64-2aaf-4135-9f4f-9b36d877cdc4--
..
..
..
..
..
..
Anyone know how to get this to happen?
Otherwise, I'm quite pleased with the new MailMessage setup.

Thanks!
-Will
Will - 09 Jul 2005 12:05 GMT
ARGH! I'm 0 for 3...

That is, I've only had to ask 3 questions here my entire career and none
have got replies.

Do I smell or something? (that doesn't count as question #4)
-Will
Blair Nygren - 26 Aug 2005 14:36 GMT
I don't get replies either.  But here's the best this I can sugest.  You
already created the HTML body in message.body = @.... therefore you shouldn't
have to create the attachment add functionality.  I would not do the HTML
body directly but let the message class build it by using
AutoGenerateHtmlBody = true.  I think that is something to try.
Anyway it's a reply.

Signature

Blair Nygren
Client Profiles Inc.

> ARGH! I'm 0 for 3...
>
[quoted text clipped - 3 lines]
> Do I smell or something? (that doesn't count as question #4)
> -Will

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.