windows 使用 C# 和 GoDaddy 使用 smtp.secureserver.net 发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7592093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending email with smtp.secureserver.net with C# and GoDaddy
提问by Rob
this is driving me absolutely crazy. I am trying to send an email through a web service written in C# through GoDaddy's servers (smtp.secureserver.net) but for some reason it's not working. Here's my code:
这让我非常疯狂。我正在尝试通过 GoDaddy 的服务器 (smtp.secureserver.net) 通过用 C# 编写的 Web 服务发送电子邮件,但由于某种原因它不起作用。这是我的代码:
public static void SendMessage(string mailFrom, string mailFromDisplayName, string[] mailTo, string[] mailCc, string subject, string body)
{
try
{
using (SmtpClient client = new SmtpClient("smtpout.secureserver.net"))
{
client.Credentials = new NetworkCredential("[email protected]", "mypassword");
client.EnableSsl = true;
//client.Credentials = CredentialCache.DefaultNetworkCredentials;
//client.DeliveryMethod = SmtpDeliveryMethod.Network;
string to = mailTo != null ? string.Join(",", mailTo) : null;
string cc = mailCc != null ? string.Join(",", mailCc) : null;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(mailFrom, mailFromDisplayName);
mail.To.Add(to);
if (cc != null)
{
mail.CC.Add(cc);
}
mail.Subject = subject;
mail.Body = body.Replace(Environment.NewLine, "<BR>");
mail.IsBodyHtml = true;
client.Send(mail);
}
}
catch (Exception ex)
{
// exception handling
}
}
string[] mailTo = { "[email protected]" };
SendMessage("[email protected]", "Test Email", mailTo, null, "Secure Server Test", "Testing... Sent at: " + DateTime.Now);
回答by Rob
GOT IT!!! Need to remove the line "client.EnableSsl = true;" because godaddy does not accept secure connections.
知道了!!!需要删除“client.EnableSsl = true;”这一行 因为godaddy 不接受安全连接。
回答by Dominik Ras
I had a similar issue. In my case setting the value of client object's .Port public property was the problem.
我有一个类似的问题。在我的情况下,设置客户端对象的 .Port 公共属性的值是问题所在。
Right now, I am not setting that value at all and emails arrive quickly, even with attachments.
现在,我根本没有设置该值,即使有附件,电子邮件也会很快到达。