Click here to Skip to main content
15,887,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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,
Posted
Updated 8-Jun-15 21:31pm
v2

1 solution

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.

Edit: also worth checking there isn't a firewall issue between your server and the smtp server on that port.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900