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

后端 未结 8 567
悲&欢浪女
悲&欢浪女 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:24

    Finally, Works!

    Put smtpClient.UseDefaultCredentials = false; after smtpClient.Credentials = credentials; then problem resolved!

                SmtpClient smtpClient = new SmtpClient(smtpServerName);                          
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(smtpUName, smtpUNamePwd);
    
                smtpClient.Credentials = credentials;
                smtpClient.UseDefaultCredentials = false;  <-- Set This Line After Credentials
    
                smtpClient.Send(mailMsg);
                smtpClient = null;
                mailMsg.Dispose();
    

提交回复
热议问题