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.
using Microsoft.AspNet.Identity;
using SendGrid;
using System.Configuration;
using System.Net;
using System.Threading.Tasks;
namespace MyInfoOnline.Controllers
{
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
return configSendGridasync(message);
}
private Task configSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
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(
ConfigurationManager.AppSettings["mailAccount"],
ConfigurationManager.AppSettings["mailPassword"]
);
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
if (transportWeb != null)
{
return transportWeb.DeliverAsync(myMessage);
}
else
{
return Task.FromResult(0);
}
}
}
}
IdentityMessage myMessage = CreateGridMessage("myemail@gmail.com", "New Info Sumbitted", User.Identity + " has submitted a new info.");
EmailService emailService = new EmailService();
await emailService.SendAsync(myMessage);
Lynn
Please mark replies that have helped you as answers.
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.
Best Regards,
Jambor
Jambor
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
Contributor
2398 Points
1104 Posts
SendGrid does not send emails but no error either
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.
Please mark replies that have helped you as answers.
Contributor
2398 Points
1104 Posts
Re: SendGrid does not send emails but no error either
Jun 05, 2016 02:34 PM|lberan|LINK
Can anybody help? Any help will be highly appreciated!
Please mark replies that have helped you as answers.
Contributor
3325 Points
403 Posts
Re: SendGrid does not send emails but no error either
Jun 06, 2016 02:15 AM|Jamobor yao - MSFT|LINK
Hi,
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.
Best Regards,
Jambor
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
Contributor
2398 Points
1104 Posts
Re: SendGrid does not send emails but no error either
Jun 07, 2016 12:05 AM|lberan|LINK
Thank you, Jambor! That sample code you recommended worked.
Please mark replies that have helped you as answers.