Код: Выделить всё
public static void SendMail(string emailAddresses, string subject, string body, bool isHtml)
{
var currentSecurityProtocol = ServicePointManager.SecurityProtocol;
try
{
using (var smtp = new SmtpClient(MailServer))
{
/*
* Define the credentials to use the SMTP server
* and security protocol
*/
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(MailUser, MailPassword);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // MailSecurityProtocol;
smtp.EnableSsl = true;
smtp.Port = MailPort;
/*
* Sends the email message
*/
using (var email = new MailMessage())
{
email.From =
email.Sender = new MailAddress(MailFrom);
email.ReplyToList.Add(new MailAddress(MailFrom));
var Combined_Addresses = emailAddresses;
var addrs = Combined_Addresses.Split(';');
foreach (var addr in addrs)
{
if (string.IsNullOrEmpty(addr))
continue;
email.To.Add(addr);
}
email.Subject = subject;
email.IsBodyHtml = isHtml;
email.SubjectEncoding = System.Text.Encoding.UTF8;
if (body.Length != 0)
{
email.Body = body;
email.BodyEncoding = System.Text.Encoding.UTF8;
}
smtp.Send(email);
}
}
}
catch (Exception ex)
{
Extensions.LogException(null, ex);
}
finally
{
ServicePointManager.SecurityProtocol = currentSecurityProtocol;
}
}
Если я попытаюсь отправить письмо на неверный адрес, оно будет возвращено.< /p>
Итак, я считаю, что это какая-то проблема с SMTP, но понятия не имею, в чем именно.
Буду признателен за любую подсказку.>
Подробнее здесь: https://stackoverflow.com/questions/786 ... -exception
Мобильная версия