我的一个Windows应用程序需要使用POP和SMTP协议发送和接收电子邮件。我们的电子邮件服务器将在公司外部。因此,我们现在模拟这种情况,我们使用Gmail帐户发送和接收电子邮件。据我所知,它需要代理详细信息才能连接到低谷代理服务器。我试图在app.config文件中配置代理详细信息。但它不起作用。它在发送电子邮件时抛出异常Failure sending email
。有人知道如何通过代理连接到外部电子邮件服务器?如何通过Gmail通过代理以编程方式发送电子邮件
我的代码
var fromAddress = new MailAddress("[email protected]", "From Name");
var toAddress = new MailAddress("[email protected]", "To Name");
const string fromPassword = "nayana12345";
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 465,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
try{
smtp.Send(message);
}catch(Exception ex){
MessageBox.Show(ex.Message);
}
}
的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy>
<proxy usesystemdefault="False" proxyaddress="http://123.456.78.90:8000" bypassonlocal="True" autoDetect="False" />
</defaultProxy>
</system.net>
</configuration>
尝试端口号码587 –
谢谢罗尼,我已经尝试过这个港口。但不能。 –
@NayanaAdassuriya可能是你正在寻找的答案可在https://stackoverflow.com/questions/19446001/send-smtp-mail-from-gmail-live-aol-or-yahoo-accounts-when-my-pc- is-connected-v/42719817#42719817 – dbw