14
전자 메일 클라이언트가 HTML을 처리 할 수없는 사람들을 위해 일반 텍스트 구성 요소와 HTML 구성 요소가 포함 된 다중 부분 MIME 메시지를 보내려고합니다. System.Net.Mail.MailMessage
클래스는이를 지원하지 않는 것으로 보입니다. 어떻게 할 수 있니?C#에서 여러 부분으로 된 MIME 메시지를 보내는 방법은 무엇입니까?
전자 메일 클라이언트가 HTML을 처리 할 수없는 사람들을 위해 일반 텍스트 구성 요소와 HTML 구성 요소가 포함 된 다중 부분 MIME 메시지를 보내려고합니다. System.Net.Mail.MailMessage
클래스는이를 지원하지 않는 것으로 보입니다. 어떻게 할 수 있니?C#에서 여러 부분으로 된 MIME 메시지를 보내는 방법은 무엇입니까?
D' 오, 이건 정말 간단합니다 ...하지만 나 같은, 인터넷 검색을하기 전에 대답을 SO에보고했다, 누군가를 위해 여기에 대답을 떠날거야 ... :)
신용에 this article.
사용 AlternateViews
, 그래서 같은 :
//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);
당신이 MediaTypeNames.Text.Plain 또는 그 대신 "text/plain」와 「text의 MediaTypeNames.Text.Html를 사용할 수있는 약간 더 강력한 형식의 시스템을 원하는 경우/html " – Talon
나는 googled하고 그것은 나를 보내 : / – Beta033