使用Gmail SMTP通过代理发送电子邮件 [英] Sending email through proxy using gmail smtp

查看:976
本文介绍了使用Gmail SMTP通过代理发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要发送一些电子邮件在我的C#应用​​程序。我是在一个代理 - 这是毫无疑问为什么代码不能正常工作。这是我到目前为止有:

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>



代码

        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);
        }  



每次我得到System.Net.WebException:远程名称不能解析:smtp.gmail.com

Everytime I get System.Net.WebException: The remote name could not be resolved: 'smtp.gmail.com'

在哪里/我该如何开始调试

Where/how do I start to debug?

推荐答案

你是正确的,是后面的代理会阻止你的代码工作。该解决方案是不是这么简单。没有标准SMTP代理,我所知道的(方式有HTTP代理)。你将不得不使用SOCKS代理,并找到了一些.NET客户端为它 - 没有一个在.NET框架,但是如果谷歌.NET SOCKS代理,你应该能够找到一个

You're correct that being behind a proxy would prevent your code from working. The solution is not so simple. There is no standard "SMTP proxy" that I'm aware of (the way that there are HTTP proxies). You would have to use a SOCKS proxy and find some .NET client for it - there isn't one in the .NET framework, but if you google ".NET SOCKS proxy" you should be able to find one.

这是相当不可能的网络正在运行一个SOCKS代理,虽然如此,你很可能不得不放弃这个,只使用本地SMTP服务器。

It's fairly unlikely that your network is running a SOCKS proxy, though, so you might well have to give up on this and just use the local SMTP server.

这篇关于使用Gmail SMTP通过代理发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆