用c#和GoDaddy发送电子邮件
本文关键字:电子邮件 GoDaddy | 更新日期: 2023-09-27 18:10:04
我简直要疯了。我试图通过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("myemail@mydomain.com", "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 = { "mytestaddress@gmail.com" };
SendMessage("myemail@mydomain.com", "Test Email", mailTo, null, "Secure Server Test", "Testing... Sent at: " + DateTime.Now);
明白了!!需要删除"客户机"行。EnableSsl = true;"因为godaddy不接受安全连接
我也遇到过类似的问题。在我的例子中,设置客户端对象的. port公共属性的值是问题所在。
现在,我根本没有设置这个值,电子邮件很快就会到达,即使有附件。