本文整理匯總了C#中SendGrid.SendGridMessage.CreateMimeMessage方法的典型用法代碼示例。如果您正苦於以下問題:C# SendGridMessage.CreateMimeMessage方法的具體用法?C# SendGridMessage.CreateMimeMessage怎麽用?C# SendGridMessage.CreateMimeMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SendGrid.SendGridMessage
的用法示例。
在下文中一共展示了SendGridMessage.CreateMimeMessage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateMimeMessage
public void CreateMimeMessage()
{
var message = new SendGridMessage();
var attachment = Path.GetTempFileName();
var text = "this is a test";
var html = "<b>This<\b> is a better test";
var headers = new KeyValuePair<String, String>("custom", "header");
message.AddAttachment(attachment);
message.Text = text;
message.Html = html;
message.AddTo("[email protected]");
message.From = new MailAddress("[email protected]");
message.AddHeaders(new Dictionary<string, string> {{headers.Key, headers.Value}});
message.EnableGravatar();
var mime = message.CreateMimeMessage();
var sr = new StreamReader(mime.AlternateViews[0].ContentStream);
var result = sr.ReadToEnd();
Assert.AreEqual(text, result);
sr = new StreamReader(mime.AlternateViews[1].ContentStream);
result = sr.ReadToEnd();
Assert.AreEqual(html, result);
result = mime.Headers.Get(headers.Key);
Assert.AreEqual(headers.Value, result);
result = mime.Headers.Get("X-Smtpapi");
var expected = "{\"filters\" : {\"gravatar\" : {\"settings\" : {\"enable\" : \"1\"}}}}";
Assert.AreEqual(expected, result);
result = mime.Attachments[0].Name;
Assert.AreEqual(Path.GetFileName(attachment), result);
}