我已經創建了一個聯繫人頁面和聯繫人模型,它具有From
Subject
和Message
作爲字符串值。現在,當我嘗試使用下面的代碼從我的開發環境發送電子郵件時,它不起作用。我瀏覽了一下尋找一個解決方案,但有幾件事情我不清楚,因爲我沒有經常處理這個問題。聯繫表格電子郵件不能正常工作
這是我用來發送電子郵件的方法。評論部分也是其中的一個嘗試。 我得到的錯誤是:System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
我意識到這可能與我在dev.env上有關係,是嗎?我究竟做錯了什麼?
public class Email
{
public void Send(Contact contact)
{
MailMessage mail = new MailMessage(
contact.From,
ConfigurationManager.AppSettings["ContactEmail"],
contact.Subject,
contact.Message);
//new SmtpClient().Send(mail);
WebMail.Send(ConfigurationManager.AppSettings["ContactEmail"], contact.Subject, contact.Message, null, null, null, false, null);
}
}
您是否在web.config中設置了您的smtp郵件設置? – user1477388
我做過了,但是在這裏不應該來自我輸入'From'的電子郵件。這是我不明白的部分......電子郵件實際上來自電子郵件中的「發件人」,還是僅僅是發送郵件的人,電子郵件實際上是從一些準備好的電子郵件地址到達的...... – rexdefuror
TBH我正在使用ActionMailer .NET這是真的很酷,因爲我可以使用視圖併發送這樣的電子郵件。我建議你看看它。但是,由於MVC是一個框架,發送電子郵件應該也非常容易,自從我使用ActionMailer.NET以來,我還沒有嘗試過。 – user1477388