这让我快疯了。我正在尝试通过 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("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e38e9a868e828a8fa38e9a878c8e828a8dcd808c8e" rel="noreferrer noopener nofollow">[email protected]</a>", "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 = { "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a07131e0f191e0b0e0e180f19192a0d070b030644090507" rel="noreferrer noopener nofollow">[email protected]</a>" };
SendMessage("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bed3c7dbd3dfd7d2fed3c7dad1d3dfd7d090ddd1d3" rel="noreferrer noopener nofollow">[email protected]</a>", "Test Email", mailTo, null, "Secure Server Test", "Testing... Sent at: " + DateTime.Now);
最佳答案
明白了!!!需要删除“client.EnableSsl = true;”行因为 godaddy 不接受安全连接。
关于c# - 使用 C# 和 GoDaddy 通过 smtp.secureserver.net 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7592093/