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);
答案 0 :(得分:3)
GOT IT !!!需要删除“client.EnableSsl = true;”行因为godaddy不接受安全连接。
答案 1 :(得分:0)
我有类似的问题。在我的情况下,设置客户端对象的.Port公共属性的值是问题。
现在,我根本没有设置该值,即使有附件,电子邮件也很快到达。