如何从asp.net页面发送邮件?尝试从ASP.net应用程序发送电子邮件时出错? [英] How can i send mail from asp.net page?Getting error while trying to send email from ASP.net application?
本文介绍了如何从asp.net页面发送邮件?尝试从ASP.net应用程序发送电子邮件时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我想发送邮件,我正在使用以下代码,
In my application I would like to send a mail and I am using the below code,
protected void SendMail()
{
// Gmail Address from where you send the mail
var fromAddress = "xxxxx@gmail.com";
// any address where the email will be sending
var toAddress = txtto.Text.ToString();
//Password of your gmail address
const string fromPassword = "*****";
// Passing the values and make a email formate to display
string subject = "Testing";
string body = "xxx";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com"
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 2000000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
protected void btnsend_Click(object sender, EventArgs e)
{
try
{
{
SendMail();
}
}
catch (Exception ex)
{
Response.Write("Could not send the e-mail - error" +ex.Message);
}
}
但我收到错误:
无法发送电子邮件 - 错误:发送邮件失败。
已添加代码块[/编辑]
but I getting an error:
Could not send the e-mail - error: Failure sending mail.
Code block added[/Edit]
推荐答案
你试过这种方式参考下面的链接
http ://asp.net-tutorials.com/misc/sending-mails/ [ ^ ]
你还需要在web.config中设置
参考
http:/ /community.discountasp.net/showthread.php?t=9157 [ ^ ]
Have you tried this way refer link below
http://asp.net-tutorials.com/misc/sending-mails/[^]
you also need to have setting in web.config
refer
http://community.discountasp.net/showthread.php?t=9157[^]
试用此代码:
Try out this code :
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
请参考以下链接:
http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail [ ^ ]
也查询调试器,smtp.send函数具有所有正确的值。
Please refer following link:
http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail[^]
also check with debugger that smtp.send function has all proper values.
这篇关于如何从asp.net页面发送邮件?尝试从ASP.net应用程序发送电子邮件时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文