Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I ran in to this problem a while ago as well. The problem is that SmtpClient does not support implicit SSL connections, but does support explicit connections (<a href="http://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx" rel="noreferrer">System.Net.Mail with SSL to authenticate against port 465</a>). The previous class of MailMessage (I believe .Net 1.0) did support this but has long been obsolete.</p> <p>My answer was to call the CDO (Collaborative Data Objects) (<a href="http://support.microsoft.com/kb/310212" rel="noreferrer">http://support.microsoft.com/kb/310212</a>) directly through COM using something like the following:</p> <pre><code> /// &lt;summary&gt; /// Send an electronic message using the Collaboration Data Objects (CDO). /// &lt;/summary&gt; /// &lt;remarks&gt;http://support.microsoft.com/kb/310212&lt;/remarks&gt; private void SendTestCDOMessage() { try { string yourEmail = "YourUserName@gmail.com"; CDO.Message message = new CDO.Message(); CDO.IConfiguration configuration = message.Configuration; ADODB.Fields fields = configuration.Fields; Console.WriteLine(String.Format("Configuring CDO settings...")); // Set configuration. // sendusing: cdoSendUsingPort, value 2, for sending the message using the network. // smtpauthenticate: Specifies the mechanism used when authenticating to an SMTP service over the network. // Possible values are: // - cdoAnonymous, value 0. Do not authenticate. // - cdoBasic, value 1. Use basic clear-text authentication. (Hint: This requires the use of "sendusername" and "sendpassword" fields) // - cdoNTLM, value 2. The current process security context is used to authenticate with the service. ADODB.Field field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"]; field.Value = "smtp.gmail.com"; field = fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"]; field.Value = 465; field = fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]; field.Value = CDO.CdoSendUsing.cdoSendUsingPort; field = fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"]; field.Value = CDO.CdoProtocolsAuthentication.cdoBasic; field = fields["http://schemas.microsoft.com/cdo/configuration/sendusername"]; field.Value = yourEmail; field = fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"]; field.Value = "YourPassword"; field = fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"]; field.Value = "true"; fields.Update(); Console.WriteLine(String.Format("Building CDO Message...")); message.From = yourEmail; message.To = yourEmail; message.Subject = "Test message."; message.TextBody = "This is a test message. Please disregard."; Console.WriteLine(String.Format("Attempting to connect to remote server...")); // Send message. message.Send(); Console.WriteLine("Message sent."); } catch (Exception ex) { Console.WriteLine(ex.Message); } } </code></pre> <p>Do not forget to browse through your COM references and add the "Microsoft CDO for Windows 200 Library" which should add two references: ADODB, and CDO.</p>
 

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