我有以下代碼導致'未指定SMTP主機'。 任何想法,爲什麼會發生這種情況? 非常感謝發送本地電子郵件到hotmail問題
var mailMessage = new System.Net.Mail.MailMessage();
mailMessage.To.Add(new MailAddress("[email protected]"));
mailMessage.From = new MailAddress("[email protected]");
mailMessage.Subject = "my test subject";
mailMessage.Body = "my test body";
mailMessage.IsBodyHtml = true;
var smtpClient = new SmtpClient { EnableSsl = true };
object userState = mailMessage;
smtpClient.Send(mailMessage);
我試過現在下面,它仍然無法
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("[email protected]", "password"),
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false
};
var mail = new MailMessage("[email protected]", "[email protected]", "hello", "there");
mail.Body = "Hello";
mail.Subject = "hi";
client.Send(mail);
我不知道,但是,可能是你應該設置你的端口號爲587 – 2012-02-20 13:12:22
如果說SMTP主機未指定,我敢打賭,你......沒有指定SMTP主機。請參閱http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx,小心「主機」屬性。 – 2012-02-20 13:52:43