Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Using office365 as an smtp server in Asp.Net Core

$
0
0

I want to send users emails from my webapp hosted in Azure. I've been following a tutorial and have this code (filled in with my details, of course):

public void SendEmail()
{
    var client = new SmtpClient("smtp.office365.com")
    {
        Port = 587,
        UseDefaultCredentials = false,
        Credentials = new NetworkCredential("user", "password")
    };

    var mailMessage = new MailMessage {From = new MailAddress("user")};
    mailMessage.To.Add("toaddress");
    mailMessage.Body = "Test";
    mailMessage.Subject = "Hello";
    client.Send(mailMessage);
}

However I have not had any success yet. I get a TimeoutException so I believe there is an issue with contacting the SMTP server.

Has anyone had any success with using Office365 to send emails? For clarity the company I work for does use Offce365 and I have a registered email address.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>