c# - SMTP mail errors -
i developing c# application send mail using smtp server of our company mail. following code.
mailmessage mail = new mailmessage(); smtpclient smtpserver = new smtpclient("10.203.195.48"); mail.from = new mailaddress(""); mail.to.add(""); mail.subject = "filename"; mail.body = "report"; smtpserver.host = "ip address fo smtp mail server."; smtpserver.port = 25; smtpserver.credentials = new system.net.networkcredential("", ""); smtpserver.send(mail);
but error:
mailbox unavailable.unable relay.the system doesn't have internet connection.
the following code gmail smtp using port 587. change port , smtp.
add namespace
using system.net mailmessage mymailmessage = new mailmessage(); mymailmessage.from = new mailaddress("emailid"); mymailmessage.to.add("to"); mymailmessage.subject = "feedback form"; mymailmessage.body = "this test message"; mymailmessage.isbodyhtml = true; smtpclient smtpserver = new smtpclient("smtp.gmail.com"); smtpserver.port = 587; smtpserver.credentials = new system.net.networkcredential("username","password"); smtpserver.enablessl = true; try { smtpserver.send(mymailmessage); } catch (exception ex) { ex.message("error"); }
Comments
Post a Comment