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