I have developed a C# console application sending emails to our customers when certain conditions occur. Mails are not sent when application is deployed as azure webjob.
When testing from visual studio in my development environment Mails are sent without any problems as intended, but when the application is deployed and run as an azure app-service webjob no mails are sent. The application is otherwise working as intended also when deployed as azure webjob.
public enum MailType : short { Plain, Html }
private static string MimeType(MailType type)
{ return (type == MailType.Html) ? "text/html" : "text/plain"; }
private static async Task sendMail(string to, string name, string subject, MailType mailType, string content)
{
SendGridMessage msg = new SendGridMessage();
msg.From = new EmailAddress("[email protected]", "Foo Ltd.");
msg.AddTo(to, name);
msg.Subject = subject;
msg.AddContent(MimeType(mailType), content);
SendGridClient client = new SendGridClient(SendGridAPIKey);
await client.SendEmailAsync(msg);
}
public static void SendMail(string to, string name, string subject, MailType mailType, string content)
{
sendMail(to, name, subject, mailType, content).Wait();
}
Answers to all other questions regarding this issue (a lot of developers have met this problem) focus on the code; especially the async implementation, but it seems this is not the issue. Does azure have some restrictions to the communication between the application deployed as webjob and the sendgrid server? (I am using the sendgrid and sendgrid.helpers.mail)
SendGridAPIKeyinConfigurationin azure webapp? - Joey Cai