Al usar la configuración de system.net/mail web.config para configurar mi SmtpClient, falla al entregar correos electrónicos, con un "error de protocolo" descrito mejor por la codificación y autenticación Base64 problemas:SmtpClient no se autenticará cuando se infle desde web.config
Ejemplo:
con la siguiente configuración
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="servermail.outsourced.com"
port="2525"
defaultCredentials="false"
userName="username"
password="password"/>
</smtp>
</mailSettings>
</system.net>
y el código:
var tmp = new SmtpClient();
MailMessage msg = new MailMessage();
msg.Subject = "test";
msg.From = new MailAddress("[email protected]");
msg.To.Add(new MailAddress("[email protected]"));
msg.Body = "test";
tmp.Send(msg);
genera el mensaje de error:
System.Net.Mail.SmtpException: The server committed a protocol violation The server response was: UGFzc3dvcmQ6
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException
& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
Sin embargo, en el siguiente código donde hice manualmente todas las propiedades, el código se ejecuta sin excepción y se entrega el correo electrónico.
var tmp2 = new SmtpClient("servermail.outsourced.com", 2525);
tmp2.Credentials = new NetworkCredential("username", "password");
tmp2.UseDefaultCredentials = false;
MailMessage msg = new MailMessage();
msg.Subject = "test";
msg.From = new MailAddress("[email protected]");
msg.To.Add(new MailAddress("[email protected]"));
msg.Body = "test";
tmp2.Send(msg);
Si decodifica UGFzc3dvcmQ6, obtiene "Contraseña", por lo que aparentemente hay un problema con su autenticación. Lo he probado yo mismo sin ningún problema.Posible duplicado: http://stackoverflow.com/questions/2380531/problem-in-sending-mail-with-smtpclient – thomasvdb
Esa fue mi sospecha inicial, excepto que las mismas credenciales producen un error cuando se configuran a través de la configuración web, y funcionan cuando se establece usando el código. –
¿Qué es el servidor de correo en uso? – Hawxby