在MVC中发送电子邮件 [英] Sending email in MVC
本文介绍了在MVC中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有以下代码在MVC中发送电子邮件。但是收到发送电子邮件失败错误。
Hi All,
I have the below code to send an email in MVC. But getting "Failure Sending email" error.
MailMessage message = new MailMessage();
message.From = new MailAddress("raj@mycompanyid.com");
message.To.Add(new MailAddress("rajmvj@gmail.com"));
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.UTF8;
message.Subject = "test subject";
message.Body = "test receiver";
SmtpClient client = new SmtpClient();
var credential = new NetworkCredential
{
UserName = "mysendgrid_username", // replace with valid value
Password = "mysendgrid_password" // replace with valid value
};
client.Credentials = credential;
client.Host = "smtp.sendgrid.net";
client.Port = 587;
client.EnableSsl = true;
client.Send(message);
任何帮助或建议都会被贬值。
问候,
Any help or suggestion would be apreciated.
Regards,
推荐答案
问题是你没有发送sendgrid期望的内容;你的凭据是错的,smtp服务器是错的,端口是错的,ssl配置是错的等等。请参阅sendgrid文档,因为肯定有一个简单的发送电子邮件的例子,这是他们的整个业务周围,我发现很难相信他们的文档不包括这个基本的东西。如果您找不到代码示例,请联系他们的支持寻求帮助。
编辑:还值得检查您的服务器和smtp之间没有防火墙问题该端口上的服务器。
The problem is that you're not sending what sendgrid expects; either your credentials are wrong, the smtp server is wrong, the port is wrong, ssl config is wrong etc. Consult the sendgrid documentation as there is surely a simple example of sending email, this is what their entire business is cantered around, I find it hard to believe their documentation doesn't cover something this basic. If you can't find the code samples then contact their support for help.
also worth checking there isn't a firewall issue between your server and the smtp server on that port.
这篇关于在MVC中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文