2011-03-30 21 views

cevap

32

D'oh bu gerçekten basit ... ama benim gibi, Googling önce cevabını SO üzerinde seyir geldi herkes için buraya cevabı bırakacağım ... :)

Kredi için this article.

Kullanım AlternateViews, şöyle:

//create the mail message 
var 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 
var plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", null, "text/plain"); 
//then we create the Html part 
var htmlView = AlternateView.CreateAlternateViewFromString("<b>this is bold text, and viewable by those mail clients that support html</b>", null, "text/html"); 
mail.AlternateViews.Add(plainView); 
mail.AlternateViews.Add(htmlView); 

//send the message 
var smtp = new SmtpClient("127.0.0.1"); //specify the mail server address 
smtp.Send(mail); 
+6

Eğer MediaTypeNames.Text.Plain ya da bunun yerine "metin/düz" ve "metnin MediaTypeNames.Text.Html kullanabilirsiniz biraz daha kesinlikle yazılı sistemini isterseniz/html " – Talon

+1

Ben googled ve beni SO için gönderdi: / – Beta033

İlgili konular