Reputation: 9
i am trying to send mail through asp.net using the code mentioned below. it works fine without proxy environment. but now i am working with proxy servers and use proxy settings to connect to internet. it gives error 'Failure Sending Mail' Please anyone help ?
MailMessage msg = new MailMessage("[email protected]", TextBox1.Text);
msg.Subject = TextBox2.Text;
msg.Body = TextBox3.Text;
SmtpClient s = new SmtpClient();
s.Host = "smtp.gmail.com";
s.EnableSsl = true;
s.Credentials = new NetworkCredential("[email protected]", "password");
s.Send(msg);
Upvotes: 1
Views: 2143
Reputation: 500
It would have worked from your home connection where there is no firewall, but to work same code in a company where they are using a corporate firewall, you need to request them for opening SMTP ports for your smtp server. Default is 25 gmail uses 587 and 465
Upvotes: 0
Reputation: 6802
Add this to your web.config and replace your.proxy.address with the address of proxy server:
<system.net>
<defaultProxy enabled="true">
<proxy proxyaddress="your.proxy.address"/>
</defaultProxy>
</system.net>
Upvotes: 2