Last post Jun 07, 2016 12:05 AM by lberan
Jun 04, 2016 01:10 PM|lberan|LINK
I deployed my MVC app to Azure and created SendGrid account. I followed a tutorial and have the following code. The app can submit the info successfully but no confirmation email has been received. No error message either. I checked online for solution.
One post said his code didn't send emails and no error either. However, without any change, his code just worked the next day. I am not as lucky as he was. My app still does not send emails. Your help will be highly appreciated.
public class EmailService : IIdentityMessageService
public Task SendAsync(IdentityMessage message)
private Task configSendGridasync(IdentityMessage message)
var myMessage = new SendGridMessage();
myMessage.From = new System.Net.Mail.MailAddress(
ConfigurationManager.AppSettings["mailFrom"], "Info Online");
myMessage.Subject = message.Subject;
myMessage.Text = message.Body;
myMessage.Html = message.Body;
var credentials = new NetworkCredential(
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
if (transportWeb != null)
private IdentityMessage CreateGridMessage(string strDestination, string strSubject, string strBody)
IdentityMessage message = new IdentityMessage();
message.Destination = strDestination;
message.Subject = strSubject;
message.Body = strBody;
IdentityMessage myMessage = CreateGridMessage("firstname.lastname@example.org", "New Info Sumbitted", User.Identity + " has submitted a new info.");
EmailService emailService = new EmailService();
Jun 05, 2016 02:34 PM|lberan|LINK
Can anybody help? Any help will be highly appreciated!
Jun 06, 2016 02:15 AM|Jamobor yao - MSFT|LINK
I would suggest you to add try...catch in your code to see whether it will catch any exception. You could also try this sample code:
https://github.com/sendgrid/sendgrid-csharp. The latest update was 24 days ago. I think it will have a new version. Please try it.
Jun 07, 2016 12:05 AM|lberan|LINK
Thank you, Jambor! That sample code you recommended worked.