c# - Gmail sending email timing out -


i trying send email gmail code isn't working, gives connection time out error. if make port '587' gives error:

the smtp server requires secure connection or client not authenticated. server response was: 5.5.1 authentication required. learn more at

        string email = // email         string password = // password         string smtp = // smtp.gmail.com         int port = // 465           var = new mailaddress(email, "");         var = new mailaddress(message.destination);          var client = new smtpclient()         {             host = smtp,             port = port,             enablessl = true,             deliverymethod = smtpdeliverymethod.network,             usedefaultcredentials = false,             credentials = new networkcredential(email, password)         };          var mail = new mailmessage(from, to)         {             subject = subject,             body = body,             isbodyhtml = true         };          return client.sendmail(mail);     } 

i have used similar code yours in past , worked, port number used 587. code:

smtpclient client = new smtpclient                                     {                                         host = "smtp.gmail.com",                                         port = 587,                                         enablessl = true,                                         deliverymethod = smtpdeliverymethod.network,                                         usedefaultcredentials = false,                                         credentials = new networkcredential("gmail_login", "gmail_password")                                     }; using( var message = new mailmessage("your_emailaddress", "destination_email")                               {                                   subject ="subject",                                   body = "body"                               }) client.send(message); 

if logging new destination/timezone should first log in through web browser , confirm :)


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -