我已经创建了一个联系人页面和联系人模型,它以From、Subject和Message作为字符串值。现在,当我尝试使用下面的代码从我的开发环境发送电子邮件时,它将无法工作。我浏览了一下,寻找解决方案,但有几件事我不清楚,因为我不经常处理这个问题。
这是我用来发送电子邮件的方法。注释部分也是其中一种尝试。我得到的错误是:System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
我意识到这可能与我在dev.env上的行为有关,是吗?我做错了什么?
public class Email
{
public void Send(Contact contact)
{
MailMessage mail = new MailMessage(
contact.From,
ConfigurationManager.AppSettings["ContactEmail"],
contact.Subject,
contact.Message);
//new SmtpClient().Send(mail);
WebMail.Send(ConfigurationManager.AppSettings["ContactEmail"], contact.Subject, contact.Message, null, null, null, false, null);
}
}发布于 2012-09-14 03:56:16
你能像这样发邮件吗?
internal static void SendEmail(MailAddress fromAddress, MailAddress toAddress, string subject, string body)
{
var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
};
var client = new SmtpClient("smtpServerName");
client.Send(message);
}发布于 2012-09-14 03:42:04
我认为您需要检查配置文件中的端口号。
https://stackoverflow.com/questions/12413581
复制相似问题