Send SMTP email using System.Net.Mail via Exchange Online (Office 365)

后端 未结 8 564
悲&欢浪女
悲&欢浪女 2020-11-29 23:34

We are testing the new Office 365 beta, and i have a mail account on the Exchange Online service. Now I\'m trying to connect a LOB application that can send smtp emails from

8条回答
  •  执念已碎
    2020-11-30 00:32

    Office 365 use two servers, smtp server and protect extended sever.

    First server is smtp.office365.com (property Host of smtp client) and second server is STARTTLS/smtp.office365.com (property TargetName of smtp client). Another thing is must put Usedefaultcredential =false before set networkcredentials.

        client.UseDefaultCredentials = False
        client.Credentials = New NetworkCredential("user@domain.com", "Password")
        client.Host = "smtp.office365.com"
        client.EnableSsl = true
        client.TargetName = "STARTTLS/smtp.office365.com"
        client.Port = 587
    
        client.Send(mail)
    

提交回复
热议问题