1

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("xyz@gmail.com", 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("xyz@gmail.com", "password");
s.Send(msg);
Dhiraj
  • 9
  • 5

2 Answers2

2

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>
Waqas
  • 6,812
  • 2
  • 33
  • 50
  • Hi waqas, thanks for the suggestion but i've tried this code and Again it shows same error message 'Failure sending mail' Please help – Dhiraj Oct 04 '11 at 09:20
0

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

Rahul Patel
  • 500
  • 3
  • 11