我有一個按鈕的事件,只需通過電子郵件發送給我,無論用戶輸入什麼。我收到消息很好....主題....消息。但從電子郵件部分只是從我自己(與它將要去的那個一樣)MailMessage ASP.NET錯誤的電子郵件?
我該如何顯示他們輸入的任何電子郵件地址?
我正在使用gmail smtp到我設置的gmail帳戶。
有MAILMESSAGE 4個參數(從,到,主題,正文)
txtEmail.Text不正確把握他們的電子郵件地址。
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
this.toEmail = "[email protected]";
this.subject = txtSubject.Text;
this.fromEmail = txtEmail.Text;
this.comment = txtComment.Text;
message = new MailMessage(fromEmail, toEmail, subject, comment);
smtp.Send(message);
message.Dispose();
}
我試着像下面這樣的建議......並仍然從我自己展示。
message = new MailMessage(ReplyToList[0].toString(), toEmail, subject, comment);
我甚至試過這樣做,仍然顯示從我自己。我甚至通過代碼來確保它保存着不同的電子郵件地址。
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
this.subject = txtSubject.Text;
this.comment = txtComment.Text;
to = new MailAddress("[email protected]");
from = new MailAddress(txtEmail.Text);
MailMessage message = new MailMessage(from, to);
message.Subject = txtSubject.Text;
message.Body = txtComment.Text;
message.Headers.Add("Reply-To", txtEmail.Text);
smtp.Send(message);
message.Dispose();
}
在代碼中,我就叫我的web.config SmtpClient client = new SmtpClient();
然後,我有
<mailSettings>
<smtp from="bob">
<network host="smtp.gmail.com" port="587" userName="myemail" password="mypassword" enableSsl="true"/>
</smtp>
</mailSettings>
任何幫助嗎?
我知道有些郵件服務器將改寫自/來源:基於該認證用戶(我假設你'做smtp認證)作爲一項安全功能。根據您的意圖,使用回覆標題可能會更簡單/更輕鬆 - 請參閱http://msdn.microsoft.com/zh-cn/library/system.net.mail.mailmessage.replytolist。 aspx - 或者,如果您想驗證重寫是怎麼回事,請運行您自己的郵件服務器進行測試(我喜歡hMailServer - http://www.hmailserver.com/) – 2011-02-24 05:08:09
好的,我嘗試了下面的內容像這樣的東西,仍然沒有工作。 message = new MailMessage(ReplyToList [0] .toString(),toEmail,subject,comment); – timmy 2011-02-24 06:25:19
你的smtp是如何設置的?你連接了哪個STMP服務器?您是否認證gmail服務器?如果是這樣,它可能會阻止您更改「發件人」地址以防止垃圾郵件等......我使用NetworkCredentials對我的公司Exchange服務器進行身份驗證時,從未遇到過這種情況。 – CodeMonkeyKing 2011-02-24 06:35:39