Note that there are some explanatory texts on larger screens.

plurals
  1. POSmtpClient won't authenticate when inflated from web.config
    primarykey
    data
    text
    <p>When using the system.net/mail web.config settings to configure my SmtpClient, it fails to deliver emails, with an "protocol error" described best by Base64 encoding and authentication problems:</p> <p>Example:<br> With the following Config</p> <pre><code>&lt;system.net&gt; &lt;mailSettings&gt; &lt;smtp from="email@server.com"&gt; &lt;network host="servermail.outsourced.com" port="2525" defaultCredentials="false" userName="username" password="password"/&gt; &lt;/smtp&gt; &lt;/mailSettings&gt; &lt;/system.net&gt; </code></pre> <p>And the Code:</p> <pre><code>var tmp = new SmtpClient(); MailMessage msg = new MailMessage(); msg.Subject = "test"; msg.From = new MailAddress("me@server.com"); msg.To.Add(new MailAddress("me@server.com")); msg.Body = "test"; tmp.Send(msg); </code></pre> <p>Produces the error message:</p> <pre><code>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 &amp; exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) </code></pre> <p>However, in the following code where I manually set all the properties, the code runs without exception and the email is delivered.</p> <pre><code>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("me@server.com"); msg.To.Add(new MailAddress("me@server.com")); msg.Body = "test"; tmp2.Send(msg); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload