D
D
DeltaToster2017-11-26 13:20:33
.NET
DeltaToster, 2017-11-26 13:20:33

Why doesn't Sending E-mail to Azure (C#) work?

There is a standard implementation of sending E-mail via SmtpClient

void SendEmail(string mailSubject, string mailBody, Stream photoStream = null)
            {
                try
                {
                    MailMessage mail = new MailMessage();
                    mail.From = new MailAddress(AppSettings.SendEmail);
                    mail.To.Add(AppSettings.GetEmail);
                    mail.Subject = mailSubject;
                    mail.Body = mailBody;
                    mail.IsBodyHtml = true; 
                    if (photoStream != null)
                    {
                        mail.Attachments.Add(new Attachment(photoStream, "Attached photo", "image/jpeg"));
                    }
                    using (SmtpClient smtp = new SmtpClient(AppSettings.SMTP_Address, AppSettings.SMTP_Port))
                    {
                        smtp.Credentials = new NetworkCredential(AppSettings.SendEmail, AppSettings.SendEmailPassword);
                        smtp.EnableSsl = AppSettings.SSL;
                        smtp.Send(mail); 
                    }
                    client.SendTextMessageAsync(chatId, "Сообщение отправлено");
                }
                catch (Exception e)
                {
                    client.SendTextMessageAsync(chatId, e.Message);
                }
            }

When you run the application on a computer, everything works, but after publishing to Azure, it displays a TimeOut or Error 5.5.4 Error: send AUTH command first error, depending on the SMTP port. Is there a solution to this problem?
AppSettings.SMTP_Address = "smtp.yandex.ru";
AppSettings.SMTP_Port = 25;
AppSettings.SSL = true;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2017-11-26
@SaNNy32

You must first be authenticated on the smtp server before sending mail

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question