我想從C#winform應用程序發送電子郵件,我的Internet連接使用代理。使用CDO通過代理髮送電子郵件
這是我迄今所做
WebProxy proxy = WebProxy.GetDefaultProxy();
Console.WriteLine(proxy.Address);
if (proxy.Address!=null)
{
try
{
MailMessage oMsg = new MailMessage();
// TODO: Replace with sender e-mail address.
oMsg.From = fromGmailAddress;
// TODO: Replace with recipient e-mail address.
oMsg.To = toAddress;
oMsg.Subject = "Send Using Web Mail";
// SEND IN HTML FORMAT (comment this line to send plain text).
oMsg.BodyFormat = MailFormat.Html;
// HTML Body (remove HTML tags for plain text).
oMsg.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>";
oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);
oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com");
oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2);
oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/urlproxyserver", proxy.Address.Host);
oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/proxyserverport", proxy.Address.Port);
oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", true);
oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", gmailUsername);
oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", gmailPassword);
SmtpMail.SmtpServer.Insert(0,"smtp.gmail.com");
SmtpMail.Send(oMsg);
oMsg = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
它拋出一個異常,運輸未能連接到服務器。 我已經嘗試過465,587和25端口的Gmail的SMTP服務器。什麼都沒有
我一直在通過網絡閱讀有關代理服務器可能無法啓用電子郵件發送的可能性。如果我閱讀或理解錯誤,請糾正我的錯誤?由於此代理允許我在使用瀏覽器時登錄gmail帳戶。
任何幫助將不勝感激。
問候
我沒想到網絡代理通常支持的非HTTP通信。你確定你不想在這裏使用SOCKS代理嗎? – 2012-02-09 15:06:41
@ M.Babcock任何指向該教程的鏈接?我怎樣才能做到這一點? – nightWatcher 2012-02-09 15:11:35
可能的重複[是否有.NET庫通過PROXY發送電子郵件?](http://stackoverflow.com/questions/3156753/is-there-net-library-for-email-sending-via-proxy) – 2012-02-09 15:16:26