c# - Error in Sending Email via a SMTP Client -


this may trivial couldn't figure out why getting error message when run code. looked of relative questions on same website eg sending email through gmail smtp server c# none of them helpful. willing please? using different assemblies acceptable. if got working solution appreciated.

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

here code

system.net.mail.mailmessage message = new system.net.mail.mailmessage();       message.from = new mailaddress("bob@googlemail.com"); message.to.add("bob@hotmail.com"); message.subject = "hello"; message.body = "hello bob "; message.deliverynotificationoptions = deliverynotificationoptions.onfailure;  smtpclient smtpclient = new smtpclient("smtp.gmail.com", 587); smtpclient.enablessl = true; smtpclient.deliverymethod = smtpdeliverymethod.network; smtpclient.usedefaultcredentials = false; smtpclient.credentials = new networkcredential("mygooglemailaccount",                                                 "mygooglemailpassword");  smtpclient.send(message.from.tostring(), message.to.tostring(),                  message.subject, message.body);    

i don't think there's wrong code other e-mail addresses. used code send e-mail gmail personal account (ran in linqpad, actually). replace 3 string values valid values accounts , should go:

mailmessage message = new system.net.mail.mailmessage();  string fromemail = "myaddr@gmail.com"; string frompw = "mypw"; string toemail = "recipient@receiver.com"; message.from = new mailaddress(fromemail); message.to.add(toemail); message.subject = "hello"; message.body = "hello bob "; message.deliverynotificationoptions = deliverynotificationoptions.onfailure;  using(smtpclient smtpclient = new smtpclient("smtp.gmail.com", 587)) {     smtpclient.enablessl = true;     smtpclient.deliverymethod = smtpdeliverymethod.network;     smtpclient.usedefaultcredentials = false;     smtpclient.credentials = new networkcredential(fromemail, frompw);      smtpclient.send(message.from.tostring(), message.to.tostring(),                      message.subject, message.body);    } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -