Home > Software design >  SMTP Outlook can't send Emails
SMTP Outlook can't send Emails

Time:04-02

i'm stuck in this problem when button click it always says "Failure to send email" I try several host like smtp.office365.com, pod51015.outlook.com and ports like 465, 25 and nothing seems to work

                string _sender = "myEmail.com";
                string _password = "myPass";

                SmtpClient client = new SmtpClient("smtp-mail.outlook.com");

                client.Port = 587;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                System.Net.NetworkCredential credentials =
                    new System.Net.NetworkCredential(_sender, _password);
                client.EnableSsl = true;
                client.Credentials = credentials;

                MailMessage message = new MailMessage(_sender, "toEmail.com");
                message.Subject = "mySubject";
                message.Body = "myBody";
                client.Send(message);

CTTO of this code which I also found in this forum which seem they worked for them.

CodePudding user response:

Office 365 SMTP servers no longer allow Basic auth by default - see https://docs.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/deprecation-of-basic-authentication-exchange-online

CodePudding user response:

Your code looks like mine, except I did force .NET to use TLS 1.2. TLS 1.1 was deprecated by office365.com in January, and this caused problems with my application.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  • Related