本文整理汇总了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);
}