Answer the question
In order to leave comments, you need to log in
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);
}
}
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
You must first be authenticated on the smtp server before sending mail
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question