Byte
Byte

Reputation: 27

SMTP Outlook can't send Emails

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.

Upvotes: 0

Views: 2985

Answers (3)

Ratul
Ratul

Reputation: 43

Let's try this workaround, it could be helpful.

  • Enable Legacy TLS: Set-TransportConfig -AllowLegacyTLSClients $true​
  • Confirm Legacy TLS is set: Get-TransportConfig | Format-List AllowLegacyTLSClients

Change the SMTP endpoint to smtp-legacy.office365.com

Upvotes: 0

A. Niese
A. Niese

Reputation: 409

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;

Upvotes: 1

Related Questions