Sending email through proxy using gmail smtp
Posted
by baron
on Stack Overflow
See other posts from Stack Overflow
or by baron
Published on 2010-04-15T05:16:20Z
Indexed on
2010/04/15
5:23 UTC
Read the original article
Hit count: 1030
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?
© Stack Overflow or respective owner