本文整理汇总了C#中System.Net.Mail.MailAddress.Any方法的典型用法代码示例。如果您正苦于以下问题:C# MailAddress.Any方法的具体用法?C# MailAddress.Any怎么用?C# MailAddress.Any使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.MailAddress
的用法示例。
在下文中一共展示了MailAddress.Any方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMailSmtp
public void SendMailSmtp(string subject, string body, bool isBodyHtml, MailAddress[] mailTo, MailAddress mailFrom)
{
if (mailTo == null || !mailTo.Any()) throw new Exception("Не указаны получатели письма!");
if (String.IsNullOrEmpty(mailFrom.Address)) mailFrom = defaultMailFrom;
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//if (!String.IsNullOrEmpty(settings.Login))
//{
// client.Credentials = new NetworkCredential(settings.Login, settings.Password);
// mail.From = new MailAddress(settings.Login);
//}
//else
//{
mail.From = mailFrom;
//}
client.EnableSsl = false;//settings.EnableSsl;
foreach (MailAddress mailAddress in mailTo)
{
mail.To.Add(mailAddress);
}
//Шлем копию письма если надо
//if (!String.IsNullOrEmpty(settings.MailCopyTo))
//{
// mail.CC.Add(new MailAddress(settings.MailCopyTo));
//}
//else
//{
// mail.CC.Clear();
//}
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = isBodyHtml;
client.Host = "ums-1";
client.Send(mail);
}
示例2: SendMailSmtp
public static void SendMailSmtp(string subject, string body, bool isBodyHtml, MailAddress[] mailTo, MailAddress[] hiddenMailTo, MailAddress mailFrom, bool isTest = false)
{
if ((mailTo == null || !mailTo.Any()) && (hiddenMailTo == null || !hiddenMailTo.Any())) throw new Exception("Не указаны получатели письма!");
if (mailFrom == null || String.IsNullOrEmpty(mailFrom.Address)) mailFrom = defaultMailFrom;
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.From = mailFrom;
client.EnableSsl = false;
if (mailTo != null)
{
foreach (MailAddress mailAddress in mailTo)
{
mail.To.Add(mailAddress);
}
}
if (hiddenMailTo != null)
{
foreach (MailAddress mailAddress in hiddenMailTo)
{
mail.Bcc.Add(mailAddress);
}
}
if (isTest)
{
mail.To.Clear();
mail.CC.Clear();
mail.Bcc.Clear();
mail.Bcc.Add(new MailAddress("[email protected]"));
//mail.Bcc.Add(new MailAddress("[email protected]"));
}
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = isBodyHtml;
client.Host = "ums-1";
client.Send(mail);
}
示例3: SendMailSmtp
public static void SendMailSmtp(string subject, string body, bool isBodyHtml, MailAddress[] mailTo, MailAddress[] hiddenMailTo = null, MailAddress mailFrom = null, AttachmentFile file = null, bool isTest = false)
{
if (!mailTo.Any() && (hiddenMailTo == null || !hiddenMailTo.Any())) throw new Exception("Не указаны получатели письма!");
if (mailFrom == null || String.IsNullOrEmpty(mailFrom.Address)) mailFrom = defaultMailFrom;
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.From = mailFrom;
client.EnableSsl = false;
if (ConfigurationManager.AppSettings["Environment"].Equals("Production") && !isTest)
{
if (mailTo != null)
{
foreach (MailAddress mailAddress in mailTo)
{
if (String.IsNullOrEmpty(mailAddress.Address)) continue;
mail.To.Add(mailAddress);
}
}
if (hiddenMailTo != null)
{
foreach (MailAddress mailAddress in hiddenMailTo)
{
if (String.IsNullOrEmpty(mailAddress.Address)) continue;
mail.CC.Add(mailAddress);
}
}
}
else
{
string[] testMails = ConfigurationManager.AppSettings["Emails4Test"].Split('|');
foreach (var email in testMails)
{
if (String.IsNullOrEmpty(email)) continue;
mail.To.Add(email);
}
body += "\r\n";
if (mailTo != null)
{
foreach (var mailAddress in mailTo)
{
body += "\r\n" + mailAddress.Address;
}
}
//Hidden recipients
if (hiddenMailTo != null)
{
foreach (var mailAddress in hiddenMailTo)
{
body += "\r\n" + mailAddress.Address;
}
}
}
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = isBodyHtml;
client.Host = "ums-1";
if (file != null && file.Data.Length > 0)
{
MemoryStream stream = new MemoryStream(file.Data);
Attachment attachment = new Attachment(stream, file.FileName, file.DataMimeType);
mail.Attachments.Add(attachment);
}
try
{
client.Send(mail);
}
catch (Exception ex)
{
throw new Exception(String.Format("Сообщение не было отправлено. Текст ошибки - {0}", ex.Message));
}
}
示例4: SendMailSmtp
public static void SendMailSmtp(string subject, string body, bool isBodyHtml, MailAddress[] mailTo, MailAddress[] hiddenMailTo, MailAddress mailFrom, AttachmentFile file = null,string login = null, string pass = null, bool isTest = false)
{
if (IsTest) isTest = true;
if ((mailTo == null || !mailTo.Any()) && (hiddenMailTo == null || !hiddenMailTo.Any())) throw new Exception("Не указаны получатели письма!");
if (mailFrom == null || String.IsNullOrEmpty(mailFrom.Address)) mailFrom = defaultMailFrom;
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient("smtp.office365.com", 587);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
if (String.IsNullOrEmpty(login))
{
login = "[email protected]";
pass = "pRgvD7TL";
}
client.Credentials = new NetworkCredential(login, pass);
mail.From = new MailAddress(login);
if (mailTo != null)
{
foreach (MailAddress mailAddress in mailTo)
{
mail.To.Add(mailAddress);
}
}
if (hiddenMailTo != null)
{
foreach (MailAddress mailAddress in hiddenMailTo)
{
mail.Bcc.Add(mailAddress);
}
}
if (isTest)
{
mail.To.Clear();
mail.CC.Clear();
mail.Bcc.Clear();
//mail.Bcc.Add(new MailAddress("[email protected]"));
string[] testMails = ConfigurationManager.AppSettings["TestMailTo"].Split('|');
foreach (string testMail in testMails)
{
mail.Bcc.Add(new MailAddress(testMail));
}
//mail.Bcc.Add(new MailAddress("[email protected]"));
}
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = isBodyHtml;
if (file != null && file.Data.Length > 0)
{
//using (MemoryStream ms = new MemoryStream())
//{
// ms.Read(file.Data, 0, file.Data.Length);
MemoryStream stream = new MemoryStream(file.Data);
Attachment attachment = new Attachment(stream, file.FileName, file.DataMimeType);
mail.Attachments.Add(attachment);
//client.Send(mail);
//}
//Attachment attachment = new Attachment(file.FileName, MediaTypeNames.Application.Octet);
//ContentDisposition disposition = attachment.ContentDisposition;
//disposition.CreationDate = File.GetCreationTime(file.FileName);
//disposition.ModificationDate = File.GetLastWriteTime(file.FileName);
//disposition.ReadDate = File.GetLastAccessTime(file.FileName);
//disposition.FileName = Path.GetFileName(file.FileName);
//disposition.Size = new FileInfo(file.FileName).Length;
//disposition.DispositionType = DispositionTypeNames.Attachment;
//mail.Attachments.Add(attachment);
}
//else
//{
client.Send(mail);
//}
}
示例5: SendMailSmtp
public static void SendMailSmtp(string subject, string body, bool isBodyHtml, MailAddress[] mailTo, MailAddress[] hiddenMailTo = null, MailAddress mailFrom = null, AttachmentFile file = null, bool isTest = false)
{
if (!mailTo.Any() && (hiddenMailTo == null || !hiddenMailTo.Any())) throw new Exception("Не указаны получатели письма!");
if (mailFrom == null || String.IsNullOrEmpty(mailFrom.Address)) mailFrom = defaultMailFrom;
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient("smtp.office365.com",587);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Credentials = new NetworkCredential("[email protected]", "pRgvD7TL");
mail.From = new MailAddress("[email protected]", String.Empty, System.Text.Encoding.UTF8);
//client.EnableSsl = false;
if (ConfigurationManager.AppSettings["Environment"].Equals("Production") && !isTest)
{
if (mailTo != null)
{
foreach (MailAddress mailAddress in mailTo)
{
if (String.IsNullOrEmpty(mailAddress.Address)) continue;
mail.To.Add(mailAddress);
}
}
if (hiddenMailTo != null)
{
foreach (MailAddress mailAddress in hiddenMailTo)
{
if (String.IsNullOrEmpty(mailAddress.Address)) continue;
mail.CC.Add(mailAddress);
}
}
}
else
{
string[] testMails = ConfigurationManager.AppSettings["Emails4Test"].Split('|');
foreach (var email in testMails)
{
if (String.IsNullOrEmpty(email)) continue;
mail.To.Add(email);
}
body += "\r\n";
if (mailTo != null)
{
foreach (var mailAddress in mailTo)
{
body += "\r\n" + mailAddress.Address;
}
}
//Hidden recipients
if (hiddenMailTo != null)
{
foreach (var mailAddress in hiddenMailTo)
{
body += "\r\n" + mailAddress.Address;
}
}
}
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = isBodyHtml;
client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
if (file != null && file.Data.Length > 0)
{
MemoryStream stream = new MemoryStream(file.Data);
Attachment attachment = new Attachment(stream, file.FileName, file.DataMimeType);
mail.Attachments.Add(attachment);
}
try
{
client.SendAsync(mail, mail);
}
catch (Exception ex)
{
throw new Exception(String.Format("Сообщение не было отправлено. Текст ошибки - {0}", ex.Message));
}
}
示例6: SendMailSmtp
public static void SendMailSmtp(string subject, string body, bool isBodyHtml, MailAddress[] mailTo, MailAddress[] hiddenMailTo, MailAddress mailFrom, AttachmentFile file = null, bool isTest = false)
{
if ((mailTo == null || !mailTo.Any()) && (hiddenMailTo == null || !hiddenMailTo.Any())) throw new Exception("Не указаны получатели письма!");
if (mailFrom == null || String.IsNullOrEmpty(mailFrom.Address)) mailFrom = defaultMailFrom;
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.From = mailFrom;
client.EnableSsl = false;
if (mailTo != null)
{
foreach (MailAddress mailAddress in mailTo)
{
mail.To.Add(mailAddress);
}
}
if (hiddenMailTo != null)
{
foreach (MailAddress mailAddress in hiddenMailTo)
{
mail.Bcc.Add(mailAddress);
}
}
if (isTest)
{
mail.To.Clear();
mail.CC.Clear();
mail.Bcc.Clear();
mail.Bcc.Add(new MailAddress("[email protected]"));
//mail.Bcc.Add(new MailAddress("[email protected]"));
}
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = isBodyHtml;
client.Host = "ums-1";
if (file != null && file.Data.Length > 0)
{
//using (MemoryStream ms = new MemoryStream())
//{
// ms.Read(file.Data, 0, file.Data.Length);
MemoryStream stream = new MemoryStream(file.Data);
Attachment attachment = new Attachment(stream, file.FileName, file.DataMimeType);
mail.Attachments.Add(attachment);
//client.Send(mail);
//}
//Attachment attachment = new Attachment(file.FileName, MediaTypeNames.Application.Octet);
//ContentDisposition disposition = attachment.ContentDisposition;
//disposition.CreationDate = File.GetCreationTime(file.FileName);
//disposition.ModificationDate = File.GetLastWriteTime(file.FileName);
//disposition.ReadDate = File.GetLastAccessTime(file.FileName);
//disposition.FileName = Path.GetFileName(file.FileName);
//disposition.Size = new FileInfo(file.FileName).Length;
//disposition.DispositionType = DispositionTypeNames.Attachment;
//mail.Attachments.Add(attachment);
}
//else
//{
client.Send(mail);
//}
}