everyone. I need to send a No-reply mail using C#. Network admin told me that the SMTP server is configured to send this type of mails (using any account without a password). I'm trying this:
System.Net.NetworkCredential credencials = new System.Net.NetworkCredential();
credencials.UserName = "[email protected]";
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.To.Add(email);
mail.From = new MailAddress("[email protected]");
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = message;
SmtpServer.Host = "smtpserver";
SmtpServer.Port = 25;
SmtpServer.Credentials = credencials;
SmtpServer.EnableSsl = true;
SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
SmtpServer.Send(mail);
I've tried without credentials, using Empty string as password, but nothing seems to work.
Am I forgetting any special parameter or configuration?
I think the combination of providing a username and using SSL on port 25 means authentication is tried but fails and the wrong protocol negotiation is attempted. If you change your code the following what then happens?
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.To.Add(email);
mail.From = new MailAddress("[email protected]");
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = message;
SmtpServer.Host = "smtpserver";
SmtpServer.Port = 25;
SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
try {
SmtpServer.Send(mail);
}
catch (Exception ex) {
Debug.WriteLine("Exception Message: " + ex.Message);
if (ex.InnerException != null)
Debug.WriteLine("Exception Inner: " + ex.InnerException);
}
I am assuming here that the server you are trying to use supports mail relay without authentication, which should rule out any sane configuration on the internet.