.Net : System.Net.Mail et le MultiPart

Après plusieurs recherches sur le net pour trouver le moyen d’envoyer des mails en .Net avec un body en MultiPart, j’ai trouvé cette solution :

 static void MultiPartMime()
//create the mail message
MailMessage mail = new MailMessage();

//set the addresses
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");

//set the content
mail.Subject = "This is an email";

//first we create the Plain Text part
AlternateView plainView = AlternateView.CreateAlternateViewFromString(
"This is my plain text content, viewable by those clients that don't support html",
//then we create the Html part
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(
"<b>this is bold text, and viewable by those mail clients that support html</b>",

//send the message
SmtpClient smtp = new SmtpClient(""); //specify the mail server address

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *