本文整理汇总了C#中System.Net.Mail.SmtpClient.SendMailExAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SmtpClient.SendMailExAsync方法的具体用法?C# SmtpClient.SendMailExAsync怎么用?C# SmtpClient.SendMailExAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.SmtpClient
的用法示例。
在下文中一共展示了SmtpClient.SendMailExAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmailSendAsync
public async Task EmailSendAsync(string aFrom, string aTo, string aSubject, string aMessage,
IEnumerable<string> aAttachments = null, bool aReadConfirmation = false, bool aReceiptConfirmation = false)
{
using (var mail = new MailMessage())
{
if (aReadConfirmation)
mail.Headers.Add("Disposition-Notification-To", aFrom);
if (!IsEmailValid(aFrom))
throw new ArgumentException("Sender address \"{aFrom}\" is not valid");
mail.From = new MailAddress(aFrom.Trim());
if (!IsEmailValid(aTo))
throw new ArgumentException("Recipient address \"{aTo}\" is not valid");
mail.To.Add(aTo.Trim());
mail.Subject = aSubject;
mail.Body = aMessage;
if (aAttachments != null)
foreach (var attachment in aAttachments)
mail.Attachments.Add(new Attachment(attachment));
if (aReceiptConfirmation)
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Delay |
DeliveryNotificationOptions.OnFailure |
DeliveryNotificationOptions.OnSuccess;
using (var smtpClient = new SmtpClient())
await smtpClient.SendMailExAsync(mail);
}
}