本文整理汇总了C#中System.Net.Mail.MailAddress.CheckNullObject方法的典型用法代码示例。如果您正苦于以下问题:C# MailAddress.CheckNullObject方法的具体用法?C# MailAddress.CheckNullObject怎么用?C# MailAddress.CheckNullObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.MailAddress
的用法示例。
在下文中一共展示了MailAddress.CheckNullObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateMailMessage
/// <summary>
/// Generates the mail message.
/// </summary>
/// <param name="subject">The subject.</param>
/// <param name="body">The body.</param>
/// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
/// <param name="encoding">The encoding.</param>
/// <param name="toList">To list.</param>
/// <param name="ccList">The cc list.</param>
/// <param name="bccList">The BCC list.</param>
/// <param name="attachments">The attachments.</param>
/// <param name="mailPriority">The mail priority.</param>
/// <returns>MailMessage.</returns>
/// <exception cref="InvalidObjectException">toList</exception>
public static MailMessage GenerateMailMessage(string subject, string body, bool isHtml, Encoding encoding, MailAddress[] toList, MailAddress[] ccList, MailAddress[] bccList, List<Attachment> attachments, MailPriority mailPriority = MailPriority.Normal)
{
toList.CheckNullObject(nameof(toList));
if (toList.Length == 0)
{
throw ExceptionFactory.CreateInvalidObjectException(nameof(toList));
}
var mailMessage = new MailMessage();
mailMessage.Subject = mailMessage.SafeToString(subject);
mailMessage.Body = mailMessage.SafeToString(body);
mailMessage.BodyEncoding = encoding ?? Encoding.UTF8;
mailMessage.IsBodyHtml = isHtml;
foreach (MailAddress to in toList)
{
mailMessage.To.Add(to);
}
if (ccList != null && ccList.Length > 0)
{
foreach (MailAddress cc in ccList.Where(cc => cc != null))
{
mailMessage.CC.Add(cc);
}
}
if (bccList != null && bccList.Length > 0)
{
foreach (var bcc in bccList.Where(bcc => bcc != null))
{
mailMessage.Bcc.Add(bcc);
}
}
if (attachments != null && attachments.Count > 0)
{
foreach (var attachment in attachments)
{
mailMessage.Attachments.Add(attachment);
}
}
mailMessage.Priority = mailPriority;
return mailMessage;
}