Sending email through proxy using gmail smtp
- by baron
Hello everyone,
Trying to send some email in my C# app. I am behind a proxy - which is no doubt why the code isn't working. This is what I have so far:
App.Config:
<system.net>
<defaultProxy enabled="false">
<proxy proxyaddress="xxx.xxx.xxx.xxx"/>
</defaultProxy>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="smtp.gmail.com" port="587"/>
</smtp>
</mailSettings>
</system.net>
Code:
var username = "...";
var password = "...";
var fromEmail = "...";
var toEmail = "...";
var body = "Test email body";
var subject = "Test Subject Email";
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential(username, password),
EnableSsl = true
};
try
{
client.Send(fromEmail, toEmail, subject, body);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
Everytime I get System.Net.WebException: The remote name could not be resolved: 'smtp.gmail.com'
Where/how do I start to debug?