BitrixAQA.General.Pop.SendYandexMail C# (CSharp) Method

SendYandexMail() public static method

Отправка письма на почтовый ящик
public static SendYandexMail ( string from, string password, string mailto, string subject, string message, string attachFiles = null ) : void
from string Адрес отправителя
password string пароль к почтовому ящику отправителя
mailto string Адрес получателя
subject string Тема письма
message string Сообщение
attachFiles string Присоединенные файлы
return void
        public static void SendYandexMail(string from, string password, string[] mailto, string subject, string message, string[] attachFiles = null)
        {
            try
            {
                using (SmtpClient client = new SmtpClient())
                {
                    MailMessage mail = new MailMessage();
                    mail.From = new MailAddress(from);
                    foreach (string recipient in mailto)
                        mail.To.Add(new MailAddress(recipient));
                    mail.Subject = subject;
                    mail.Body = message;
                    if (attachFiles != null)
                    {
                        foreach (string attachFile in attachFiles)
                            mail.Attachments.Add(new Attachment(attachFile));
                    }

                    client.Host = "smtp.yandex.ru";
                    client.Port = 587;
                    client.EnableSsl = true;
                    client.UseDefaultCredentials = false;
                    client.Credentials = new NetworkCredential(from.Substring(0, from.IndexOf("@")), password);
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.Send(mail);
                    mail.Dispose();
                }
            }
            catch(Exception Ex)
            {
                Log.MesError("Вероятно роблемы на стороне smtp.yandex.ru. /r/n " + Ex.Message + "/r/n" + Ex.StackTrace);
            }
        }