0
我想發一封電子郵件,但它顯示了以下錯誤:無法在asp.net應用程序發送
try
{
string filename = Server.MapPath("~/App_Data/FeedBack.txt");
string mailbody = System.IO.File.ReadAllText(filename);
mailbody = mailbody.Replace("##Name##", txtName.Text);
mailbody = mailbody.Replace("##Email##",txtEmail.Text);
mailbody = mailbody.Replace("##contact##",txtContact.Text);
mailbody = mailbody.Replace("##Commnect##",txtSuggestion.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Responce from website";
myMessage.Body = mailbody;
myMessage.From = new MailAddress("[email protected]","Amit Kumar");
myMessage.To.Add(new MailAddress("[email protected]", "Amit Verma"));
SmtpClient mysmptclient = new SmtpClient("localhost");
mysmptclient.Host = "smtp.gmail.com";
mysmptclient.Port = 587;
mysmptclient.Credentials = new System.Net.NetworkCredential("[email protected]", "Myemailpassword");
mysmptclient.Send(myMessage);
formatTable.Visible = false;
lblMail.Text = "Your Feedback has been sent successfully";
lblMail.ForeColor = Color.Green;
}
catch(Exception expt)
{
lblMail.Text = "unable to sent the feedback .Check your smpt server"+expt.Message;
lblMail.ForeColor = Color.Red;
}
我的web.config文件看起來是這樣的:
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="smtp.gmail.com" port='587' password="myemailpass" userName="[email protected]"/>
</smtp>
</mailSettings>
</system.net>
你得到什麼錯誤? – SANDEEP
我的例外信息是發送郵件失敗 –
你有沒有調試你的代碼? – SANDEEP