本文整理汇总了C#中System.Net.Mail.MailMessage.GetBodyParts方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.GetBodyParts方法的具体用法?C# MailMessage.GetBodyParts怎么用?C# MailMessage.GetBodyParts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.MailMessage
的用法示例。
在下文中一共展示了MailMessage.GetBodyParts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public static List<FormPart> Build(MailMessage message, IDictionary<string, IDictionary<string, object>> recipientVariables)
{
if (message == null)
return new List<FormPart>();
var result = new List<FormPart>
{
new SimpleFormPart("from", message.From.ToString()),
new SimpleFormPart("to",string.Join(", ", message.To)),
new SimpleFormPart("subject", message.Subject),
};
if (recipientVariables != null)
{
result.Add(new SimpleFormPart("recipient-variables", JsonConvert.SerializeObject(recipientVariables)));
}
if (message.CC.Any())
result.Add(new SimpleFormPart("cc", string.Join(", ", message.CC)));
if (message.Bcc.Any())
result.Add(new SimpleFormPart("bcc", string.Join(", ", message.Bcc)));
if(message.ReplyToList.Any())
result.Add(new SimpleFormPart("h:Reply-To", string.Join(", ", message.ReplyToList)));
result.AddRange(message.GetBodyParts());
result.AddRange(message.Attachments.Select(attachment => new AttachmentFormPart(attachment)));
return result;
}
示例2: Build
public static List<FormPart> Build(MailMessage message)
{
if (message == null)
return new List<FormPart>();
var result = new List<FormPart>
{
new SimpleFormPart("from", message.From.ToString()),
new SimpleFormPart("to",string.Join(", ", message.To)),
new SimpleFormPart("subject", message.Subject)
};
if (message.CC.Any())
result.Add(new SimpleFormPart("cc", string.Join(", ", message.CC)));
if (message.Bcc.Any())
result.Add(new SimpleFormPart("bcc", string.Join(", ", message.Bcc)));
result.AddRange(message.GetBodyParts());
result.AddRange(message.Attachments.Select(attachment => new AttachmentFormPart(attachment)));
return result;
}
示例3: Build
public static List<FormPart> Build(MailMessage message, IDictionary<string, IDictionary<string, object>> recipientVariables)
{
if (message == null)
return new List<FormPart>();
var result = new List<FormPart>
{
new SimpleFormPart("from", message.From.ToString()),
new SimpleFormPart("to",string.Join(", ", message.To)),
new SimpleFormPart("subject", message.Subject),
};
if (recipientVariables != null)
{
result.Add(new SimpleFormPart("recipient-variables", JsonConvert.SerializeObject(recipientVariables)));
}
if (message.CC.Any())
result.Add(new SimpleFormPart("cc", string.Join(", ", message.CC)));
if (message.Bcc.Any())
result.Add(new SimpleFormPart("bcc", string.Join(", ", message.Bcc)));
if(message.ReplyToList.Any())
result.Add(new SimpleFormPart("h:Reply-To", string.Join(", ", message.ReplyToList)));
// Check for the existence of any Mailgun-Variables headers
if (message.Headers.AllKeys.Contains("X-Mailgun-Variables"))
{
// Grab the Mailgun variables header values
var variableHeaders = message.Headers.GetValues("X-Mailgun-Variables");
if (variableHeaders != null)
{
// Iterate over the collection and add each tag header to the result
foreach (var variable in variableHeaders)
{
JObject customVar = JObject.Parse(variable);
foreach (var item in customVar)
{
result.Add(new SimpleFormPart(string.Format("v:{0}", item.Key), item.Value.ToString()));
}
}
}
}
result.AddRange(message.GetBodyParts());
// Check for the existense of any Mailgun Tag headers
if (message.Headers.AllKeys.Contains("X-Mailgun-Tag"))
{
// Grab the Mailgun tag header values
var tagHeaders = message.Headers.GetValues("X-Mailgun-Tag");
if (tagHeaders != null)
{
// Iterate over the collection and add each tag header to the result
foreach (var tag in tagHeaders)
{
result.Add(new SimpleFormPart("o:tag", tag));
}
}
}
result.AddRange(message.Attachments.Select(attachment => new AttachmentFormPart(attachment)));
return result;
}