I am trying to send email using Asp.net using my account....
I want to send it on a gmail account say "abc@gmail.com"
but it gives ERROR..
ErrorServer does not support secure connections.

the code is below:

try
{
  //Create Mail Message Object with content that you want to send with mail.
            System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("abc@yahoo.co.in","xyz@gmail.com",
        "This is the mail subject", "Just wanted to say Hello ");

            MyMailMessage.IsBodyHtml = false;

      System.Net.NetworkCredential mailAuthentication = new
  System.Net.NetworkCredential("abc@yahoo.co.in", "123");

   System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.mail.yahoo.com", 587);

            //Enable SSL
            mailClient.EnableSsl = true;
            mailClient.UseDefaultCredentials = false;
            mailClient.Credentials = mailAuthentication;
         
         mailClient.Send(MyMailMessage);
            this.TextBox1.Text = "SUccess";
        }
        catch(Exception ex)
        {
            this.TextBox1.Text = "Error" + ex.Message ;
        
        }

Any ideas ???

sknake commented: You should know about code tags by now. -2

Recommended Answers

All 2 Replies

Remove the below line:

mailClient.EnableSsl = true;

Hope your problem will resolve.

mailClient.Port = 587;
mailClient.EnableSsl = true;
mailsmtpClient.UseDefaultCredentials = false;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;


I was facing same issue and fixed by adding above lines.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.