i'm trying send email using c# console failing each time error says:
failure sending mail. ---> system.net.webexception: unable connect remote server ---> system.net.sockets.socketexception: attempt made access socket in way forbidden access permissions 173.194.65.109:587
this c# code:
smtpclient client = new smtpclient(); client.deliverymethod = smtpdeliverymethod.network; client.enablessl = true; client.host = "smtp.gmail.com"; client.port = 587; // setup smtp authentication system.net.networkcredential credentials = new system.net.networkcredential("myemail@gmail.com", "mypassword"); client.usedefaultcredentials = false; client.credentials = credentials; mailmessage msg = new mailmessage(); msg.from = new mailaddress("myemail@gmail.com"); msg.to.add(new mailaddress("destinationemail@gmail.com")); msg.subject = "this test email subject"; msg.isbodyhtml = true; msg.body = string.format("<html><head></head><body><b>test html email</b></body>"); client.send(msg);
i've tried use:
client.usedefaultcredentials = true;
but still no success.
this generic c# code written on web, in each forum...but not me.
i can think of 2 problems here. first port 587 not open, higly unlikely since it's standard port mail never know.
second code seems fine might have forgotten parts in app.config file. suspect.
<system.net> <mailsettings> <smtp> <network host="mail.ourorganisationemail@ourdomain.com" port="9999" username="ourorganisationemail@ourdomain.com" password="ourorganisationemailpassword"/> </smtp> </mailsettings> </system.net>
Comments
Post a Comment