Sending email through a proxy using gmail smtp

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?

+3
source share
2 answers

, -, . . "SMTP-", (, HTTP-). - SOCKS - .NET- - .NET Framework , - Google.NET SOCKS, .

, - SOCKS, , , SMTP-.

+3

- , telnet - .

DOS :

  telnet smtp.gmail.com 587

:

  220 mx.google.com ESMTP 20sm950596pzk.3

( " " ), .

telnet / " Windows", .

+8

Source: https://habr.com/ru/post/1741206/


All Articles