Forums & Blog

A SmarterTools-sponsored community.
Welcome to Forums & Blog Sign in | Join | Help
in Search

SMTP email sending using SSL connection from simple C# code

Last post 01-22-2010 2:36 AM by Usama El-Mokadem. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-08-2008 4:05 AM

    • GrZeCh
    • Top 50 Contributor
    • Joined on 05-02-2007
    • Poland
    • Posts 258

    SMTP email sending using SSL connection from simple C# code

    Hello!

    I have strange issue and maybe someone here can help me. I'm using QuickSSL SSL certificate for handling secure connections to my SmaterMail.Sending e-mails usingMS Outlooks works but when I try to send email using simple C# code:

                //create the mail message
                MailMessage mail = new MailMessage("from", "to");

                //set the content
                mail.Subject = "This is an email";
                mail.Body = "this is the body content of the email.";

                SmtpClient smtp = new SmtpClient("ssl.myhost.com", 465);
                smtp.Credentials = new NetworkCredential("username", "password");
                smtp.EnableSsl = true;
                smtp.Send(mail);

     I'm getting timeot and in SmarterMail logs I have:

    12:59:36 [ my IP ][17198118] Exception negotiating SSL certificate: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
       at System.Net.Sockets.Socket.Receive(Byte[ buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
       at System.Net.Sockets.NetworkStream.Read(Byte[ buffer, Int32 offset, Int32 size)
       --- End of inner exception stack trace ---
       at System.Net.Sockets.NetworkStream.Read(Byte[ buffer, Int32 offset, Int32 size)
       at System.Net.FixedSizeReader.ReadPacket(Byte[ buffer, Int32 offset, Int32 count)
       at System.Net.Security.SslState.StartReceiveBlob(Byte[ buffer, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[ buffer, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
       at System.Net.Security.SslStream.AuthenticateAsServer(X509Certificate serverCertificate)
       at TcpServerLib.Pooled.PooledTcpItem.ConvertToSSL(SSLSetting setting)
       at TcpServerLib.Pooled.PooledTcpServer.AcceptConnection(IAsyncResult res)

    Does anyone have any idea how to fix this?

    Thanks in advance

  • 05-12-2008 1:45 PM In reply to

    • GrZeCh
    • Top 50 Contributor
    • Joined on 05-02-2007
    • Poland
    • Posts 258

    Re: SMTP email sending using SSL connection from simple C# code

     anyone?

  • 06-15-2009 11:04 PM In reply to

    Re: SMTP email sending using SSL connection from simple C# code

     check the following link , it will explain step by step

    http://csharp.net-informations.com/communications/csharp-smtp-mail.htm

     

    liam.

     

  • 01-21-2010 5:54 PM In reply to

    Re: SMTP email sending using SSL connection from simple C# code

     I have this exact same problem. Did you ever find a solution?

  • 01-22-2010 2:36 AM In reply to

    Re: SMTP email sending using SSL connection from simple C# code

    Eng. Usama El-Mokadem
    Nothing is impossible, the word impossible itself says that: I M - Possible

Page 1 of 1 (5 items)