尝试从ASP.net应用程序发送电子邮件时出错? [英] Getting error while trying to send email from ASP.net application?
本文介绍了尝试从ASP.net应用程序发送电子邮件时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我想发送邮件,我使用下面的代码,但是我收到错误:
In my application I would like to send a mail and I am using the below code, but I get the error:
Could not send the e-mail - error: Failure sending mail.
protected void btnsend_Click(object sender, EventArgs e)
{
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add("xxx@gmail.com");
mailMessage.From = new MailAddress("xxxx@gmail.com");
mailMessage.Subject = "ASP.NET e-mail test";
mailMessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!";
SmtpClient smtpClient = new SmtpClient("smtp.your-isp.com");
smtpClient.Send(mailMessage);
Response.Write("E-mail sent!");
}
catch (Exception ex)
{
Response.Write("Could not send the e-mail - error: " + ex.Message);
}
}
这里我们没有给出发件人(来自)密码,然后系统将如何从该发件人发送邮件?
Here we are not giving the sender(from)password then how the system will send mail from that sender?
推荐答案
你得到的错误是什么?看一下这个样本:
使用ASP.NET和C#发送邮件/联系表单 [ ^ ]
What''s the error you are getting? Have a look at this sample:
Send Mail / Contact Form using ASP.NET and C#[^]
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);
这篇关于尝试从ASP.net应用程序发送电子邮件时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文