c# - SmtpException while sending Email -


i trying send email through c# code getting smtpexception

a connection attempt failed because connected party did not respond after period of time, or established connection failed because connected host has failed respond 173.194.67.109:587

here how sending email:

string hostaddress = "smtp.gmail.com"; mailmessage msg = new mailmessage(); msg.from = new mailaddress(fromemail); msg.subject = "test email"; msg.body = "hi testing invoice"; msg.isbodyhtml = true; msg.to.add(new mailaddress("ramshaafaq2012@gmail.com")); smtpclient client = new smtpclient(); client.host = hostaddress; client.enablessl = true; networkcredential creadit = new networkcredential(); creadit.username = msg.from.address; creadit.password = password; client.usedefaultcredentials = true; client.credentials = creadit; client.port = 587; client.send(msg); 

your problem here:

client.usedefaultcredentials = true; client.credentials = creadit; 

you specifying set of credentials also telling smtpclient use default credentials (i.e. windows username , password of logged-in user). set usedefaultcredentials false , use supplied credentials instead.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -