本文整理汇总了C#中System.Net.Mail.MailAddress.Select方法的典型用法代码示例。如果您正苦于以下问题:C# MailAddress.Select方法的具体用法?C# MailAddress.Select怎么用?C# MailAddress.Select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.MailAddress
的用法示例。
在下文中一共展示了MailAddress.Select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendEmailWithAttachments
public bool SendEmailWithAttachments(string AWSAccessKey, string AWSSecretKey, MailAddress From, MailAddress[] To, String Subject, System.Net.Mail.Attachment[] Attachments, String Text = null, String Html = null, MailAddress ReplyTo = null, MailAddress[] CCAddresses = null, MailAddress[] BCCAddresses = null)
{
AlternateView plainView = null;
if (Text != null)
plainView = AlternateView.CreateAlternateViewFromString(Text, Encoding.UTF8, "text/plain");
AlternateView htmlView = null;
if (Html != null)
htmlView = AlternateView.CreateAlternateViewFromString(Html, Encoding.UTF8, "text/html");
MailMessage mailMessage = new MailMessage();
mailMessage.From = From;
foreach (MailAddress toAdd in To ?? Enumerable.Empty<MailAddress>())
mailMessage.To.Add(toAdd);
foreach (MailAddress toCC in CCAddresses ?? Enumerable.Empty<MailAddress>())
mailMessage.CC.Add(toCC);
foreach (MailAddress toBcc in BCCAddresses ?? Enumerable.Empty<MailAddress>())
mailMessage.Bcc.Add(toBcc);
mailMessage.Subject = Subject;
mailMessage.SubjectEncoding = Encoding.UTF8;
if (ReplyTo != null)
{
mailMessage.ReplyTo = ReplyTo;
}
if (Text != null)
{
mailMessage.AlternateViews.Add(plainView);
}
if (Html != null)
{
mailMessage.AlternateViews.Add(htmlView);
}
foreach (System.Net.Mail.Attachment a in Attachments ?? Enumerable.Empty<System.Net.Mail.Attachment>())
{
mailMessage.Attachments.Add(a);
}
RawMessage rawMessage = new RawMessage();
using (MemoryStream memoryStream = ConvertMailMessageToMemoryStream(mailMessage))
{
rawMessage.WithData(memoryStream);
}
SendRawEmailRequest request = new SendRawEmailRequest();
request.WithRawMessage(rawMessage);
request.WithDestinations(To.Select(a => a.Address));
request.WithSource(From.Address);
AmazonSimpleEmailService ses = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(AWSAccessKey, AWSSecretKey);
try
{
SendRawEmailResponse response = ses.SendRawEmail(request);
SendRawEmailResult result = response.SendRawEmailResult;
return true;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("There was an error sending the e-mail: {0}", ex.Message));
return false;
}
}