通过mvc发送电子邮件

时间:2017-05-31 15:26:33

标签: c# asp.net asp.net-mvc email asp.net-mvc-4

我正在创建我的mvc应用。我想向注册的用户发送电子邮件。我是这样做的:

MailMessage mail = new MailMessage();
mail.To.Add(user1.email.Replace(" ", string.Empty));
mail.From = new MailAddress("declarations@virtual.mini.pw.edu.pl");
mail.Subject = "Class Declaration System user creation confirmation.";
string body = "Dear " + user1.name + ",\n This is to confirm that you have succesfully registered in the system. \n Do not reply to this message. \n Regards";
mail.Body = body;
mail.IsBodyHtml = true;
var smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Host = "poczta.mini.pw.edu.pl";
smtp.Port = 25;

一切似乎都很好。我联系了服务器的管理员,我通过正确的端口发送所有内容。但是,我收到一个错误:

Command parameter not implemented. The server response was: 5.5.2
> <WIN-KI3H68FIO4E>: Helo command rejected: need fully-qualified hostname

管理员告诉我,这是因为我试图将其作为WIN-KI3H68FIO4E发送,但它应该是something.mini.pw.edu.pl,因为我们在这里有这样的限制。如何在我的代码中更改它?

1 个答案:

答案 0 :(得分:0)

答案是编辑web.config文件并添加自定义ClientDomain。