Trying to send email to my C # application. I am for the proxy - this is, without a doubt, the reason why the code does not work. 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>
The 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);
}
Every time I get a System.Net.WebException: The remote name cannot be resolved: 'smtp.gmail.com'
Where / how to start debugging?
source
share