我在此代码中遇到问题我是新来的请帮帮我
错误是:无法发送电子邮件 - 错误:发送邮件失败。
这是我的代码:
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(emaild_id);
mailMessage.From = new MailAddress(my_email_id);
mailMessage.Subject = "Info";
mailMessage.Body = "something.....";
SmtpClient smtpClient = new SmtpClient("my site name like web.com");
smtpClient.Send(mailMessage);
}
catch (Exception ex)
{
Label1.Text="Could not send the e-mail - error: " + ex.Message;
}
答案 0 :(得分:0)
在smtp
下的web.config中输入您的<mailSettings> ... <network>
服务器设置。请查看Web配置中<mailSettings>
的规范:
http://msdn.microsoft.com/en-us/library/ms164240(v=vs.110).aspx
答案 1 :(得分:-1)
您需要配置smtp服务器。例如,如果您有gmail帐户,则可以使用gmail smtp服务器进行测试
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.Credentials = new System.Net.NetworkCredential( your gmail address, your gmail password);
client.EnableSsl = true;
client.Timeout = 3000;
client.Send(mail);
或者您可以将web.config配置为
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="smtp.gmail.com" port="587" userName="your email" password="your password" defaultCredentials="false" enableSsl="true" />
</smtp>
</mailSettings>