2

This is my mail sending code.....

    string fromAddress = "from@abc.gov.in";
    string toAddress = "darpansamani@gmail.com";
    string fromPassword = "*********";
    string subject = "Citizens Forum";
    string body = "Demo Body";


    MailMessage mail = null;

    using (mail = new MailMessage(new MailAddress(fromAddress), new MailAddress(toAddress)))
    {

        mail.Subject = subject;
        mail.Body = body;
        mail.To.Add(toAddress);

        SmtpClient smtpMail = null;
        using (smtpMail = new SmtpClient("smtp.gmail.com"))
        {
            smtpMail.Port = 587;
            smtpMail.EnableSsl = false;
            smtpMail.Credentials = new NetworkCredential(fromAddress, fromPassword);

            smtpMail.UseDefaultCredentials = false;
            smtpMail.Send(mail);
            Console.WriteLine("sent");
            Console.ReadLine();

        }

    }

This code give me error of "Unable to read data from the transport connection: net_io_connectionclosed." i am using asp.net with c# website and cant send mail to my mail address please help me Thank you

Soham
  • 4,397
  • 11
  • 43
  • 71
  • Possible duplicate of [SmtpException: Unable to read data from the transport connection: net\_io\_connectionclosed](http://stackoverflow.com/questions/20228644/smtpexception-unable-to-read-data-from-the-transport-connection-net-io-connect) – Dah Sra Mar 29 '16 at 05:22
  • Hi thx for reply i try all 3 ports given by gmail but all are not working, please give me another solution – user3831765 Mar 29 '16 at 05:29
  • Try enablessl true... (and try 3 ports that you jave found while ssl true) – Lost_In_Library Mar 29 '16 at 05:50
  • hi lost_in_liberary thx but i also try this its not working in 465 port give error "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.130.109:465" and on another port give same error as my question please give me another solution – user3831765 Mar 29 '16 at 05:57
  • can it is my system issue or i have to change any my system changes??? – user3831765 Mar 29 '16 at 05:59
  • This is old, but did you ever try port 587 and `EnableSsl`? This is the magic combination, as far as I know. – Sinjai Aug 10 '17 at 20:22

0 Answers0