PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Bug in ASP.NET 2.0: AlternateViews MIME Email

 
 
warren@support.datasearch.com.au
Guest
Posts: n/a
 
      18th Nov 2005
To add a text and body part of an email MSDN help has an example:

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref10/html/P_System_Net_Mail_MailMessage_AlternateViews.htm

Which lists the code I have below (doesn't work). I get an illegal
characters in path error. This appears to be a bug or a typo in the
code example?

public static void CreateMessageWithMultipleViews(string server, string
recipients)
{
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"(E-Mail Removed)",
recipients,
"This e-mail message has multiple views.",
"This is some plain text.");

// Construct the alternate body as HTML.
string body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0
Transitional//EN\">";
body += "<HTML><HEAD><META http-equiv=Content-Type
content=\"text/html; charset=iso-8859-1\">";
body += "</HEAD><BODY><DIV><FONT face=Arial color=#ff0000
size=2>this is some HTML text";
body += "</FONT></DIV></BODY></HTML>";

// Add the alternate body to the message.
AlternateView alternate = new AlternateView(body,
MediaTypeNames.Text.Html);
message.AlternateViews.Add(alternate);

// Send the message.
SmtpClient client = new SmtpClient(server);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);
// Display the values in the ContentType for the attachment.
ContentType c = alternate.ContentType;
Console.WriteLine("Content type");
Console.WriteLine(c.ToString());
Console.WriteLine("Boundary {0}", c.Boundary);
Console.WriteLine("CharSet {0}", c.CharSet);
Console.WriteLine("MediaType {0}", c.MediaType);
Console.WriteLine("Name {0}", c.Name);
Console.WriteLine("Parameters: {0}", c.Parameters.Count);
foreach (DictionaryEntry d in c.Parameters)
{
Console.WriteLine("{0} = {1}", d.Key, d.Value);
}
Console.WriteLine();
alternate.Dispose();
}

 
Reply With Quote
 
 
 
 
Mark Walker
Guest
Posts: n/a
 
      16th Jul 2007
This is a really old thread but I just had the same problem. Wasn't hard to
work out but in case someone else has this problem...

The overload that takes text as the first parameter is expecting a file path
for an attachment. Instead in this case you would want to convert to a
stream:

// Add the alternate body to the message.
//Convert text to stream
Stream stream = new MemoryStream(Encoding.ASCII.GetBytes(body));
AlternateView alternate = new AlternateView(stream, MediaTypeNames.Text.Html)
;
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mime email MM User Microsoft Outlook 1 17th Nov 2008 02:59 PM
Email in MIME format Mich Microsoft Outlook Discussion 0 31st Jul 2008 04:20 PM
how do i enable mime email in outlook manwendil Microsoft Outlook Installation 1 20th Feb 2008 03:36 AM
Net.Mail.MailMessage.AlternateViews problem sending html and text =?Utf-8?B?Q2FwdGFpbiBEYXZlIQ==?= Microsoft VB .NET 2 18th Aug 2007 12:02 AM
S/MIME email =?Utf-8?B?SmVyZW15?= Microsoft Dot NET 1 20th Jul 2007 06:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:44 PM.