0

exception :
enter image description here

my code :

        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient(host:"smtp.partner.outlook.cn",port:587);
        mail.From = new MailAddress("");
        mail.To.Add(    ""  );
        mail.Subject = "Test"   ;
        mail.Body = @"Test" ;
        SmtpServer.Port = 587   ;
        SmtpServer.Credentials = new System.Net.NetworkCredential(userName:"",password: "") ;
        SmtpServer.EnableSsl = true ;
        SmtpServer.Send(mail);

error msg :

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [SHAPR01CA022.CHNPR01.prod.partner.outlook.cn]

it looks like the office 365 partner in china have some different setting and cause this problem.

what i searched and tried :

Wei Lin
  • 3,591
  • 2
  • 20
  • 52
  • you need to use `microsoft.exchange.webservices.dll` / package, and a valid user – T.S. Jun 18 '20 at 05:32
  • 1
    @T.S. thanks,i'm trying your way now. – Wei Lin Jun 18 '20 at 05:34
  • 1
    Also see this : https://stackoverflow.com/questions/6244694/send-smtp-email-using-system-net-mail-via-exchange-online-office-365 I personally never used `smtpClient` against office365. But EWS client - yes. Possibly, sending email is not too bad. In my case I mostly read email but also send. – T.S. Jun 18 '20 at 05:37

0 Answers0