This link saved my life: link
here the problem that I experienced is well described: even if the username is transmitted with AUTH LOGIN, the server answers AUTH_LOGIN_Username_Challenge again.
This problem only occurs when using System.Net.Mail. The link offers the following possible solutions:
1) Use CDOSYS (does not send username with AUTH Login)
2) Use System.Web.Mail (Do not send username with AUTH Login)
3) Contact the owner of the SMTP server and fix the server.
Unfortunately, I could not use the owner of the SMTP server, so I had to use System.Web.Mail. I know that it is outdated, but, unfortunately, in such cases there is no other choice for IMO.
What is my working code:
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage(); msg.Body = message.Body; string smtpServer = "mail.business.it"; string userName = "username"; string password = "password"; int cdoBasic = 1; int cdoSendUsingPort = 2; if (userName.Length > 0) { msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer); msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25); msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort); msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic); msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName); msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); } msg.To = message.Destination; msg.From = " me@domain.it "; msg.Subject = message.Subject; msg.BodyFormat = MailFormat.Html;
This answer helped me in using System.Web.Mail.
source share