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
Post a Comment