本文整理汇总了C#中EmailMessage.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# EmailMessage.AddHeader方法的具体用法?C# EmailMessage.AddHeader怎么用?C# EmailMessage.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EmailMessage
的用法示例。
在下文中一共展示了EmailMessage.AddHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateProspectiveMailMessage
/// <summary>
/// Creates a MailMessage for the current MailAttribute instance.
/// </summary>
protected EmailMessage GenerateProspectiveMailMessage(MailAttributes mail)
{
//create base message
var message = new EmailMessage
{
FromName = mail.From.DisplayName,
FromEmail = mail.From.Address,
To = mail.To.Union(mail.Cc).Select(t => new EmailAddress(t.Address, t.DisplayName)),
BccAddress = mail.Bcc.Any() ? mail.Bcc.First().Address : null,
Subject = mail.Subject,
Important = mail.Priority == MailPriority.High ? true : false
};
// We need to set Reply-To as a custom header
if (mail.ReplyTo.Any())
{
message.AddHeader("Reply-To", string.Join(" , ", mail.ReplyTo));
}
// Adding content to the message
foreach (var view in mail.AlternateViews)
{
var reader = new StreamReader(view.ContentStream, Encoding.UTF8, true, 1024, true);
var body = reader.ReadToEnd();
if (view.ContentType.MediaType == MediaTypeNames.Text.Plain)
{
message.Text = body;
}
if (view.ContentType.MediaType == MediaTypeNames.Text.Html)
{
message.Html = body;
}
}
// Going through headers and adding them to the message
mail.Headers.ToList().ForEach(h => message.AddHeader(h.Key, h.Value));
// Adding the attachments
var attachments = new List<EmailAttachment>();
foreach (var mailAttachment in mail.Attachments.Select(attachment => ActionMailerNext.Utils.AttachmentCollection.ModifyAttachmentProperties(attachment.Key, attachment.Value, false)))
{
using (var stream = new MemoryStream())
{
mailAttachment.ContentStream.CopyTo(stream);
var base64Data = Convert.ToBase64String(stream.ToArray());
attachments.Add(new EmailAttachment
{
Content = base64Data,
Name = mailAttachment.Name,
Type = mailAttachment.ContentType.MediaType,
});
}
}
message.Attachments = attachments;
return message;
}