I have a queue triggered Azure function and it works perfectly locally. Emails are retrieved from the queue and sent when run locally. However when I publish from Visual Studio it does run. When I test in the portal it returns 404 Not found. I have both my SendGridApiKey and CloudStorageAccount setup in Application Settings, and they match what is in my local.settings.json file. I'm using an email from my SendGrid Verified domain. The sister Azure function that loads an email message into the queue run and executes fine so it's recognizing the cloudstorageaccount.
I've been following this example:
https://www.c-sharpcorner.com/article/how-to-send-email-using-sendgrid-with-azure-function-in-net-core2/
I might add that I wrote a simple sendgrid function in the portal and it works. I'm posting my code below but I don't think it's code related but rather a configuration setting or binding. I'm stumped. Please help.
My Code:
namespace AzFunctions
{
public static class SendGridEmailQueueTriggerFunction
{
[FunctionName("SendGridEmailQueueTriggerFunction")]
public static void Run([QueueTrigger("email-queue", Connection = "CloudStorageAccount")] string myQueueItem,
[SendGrid(ApiKey = "SendGridApiKey")] out SendGridMessage sendGridMessage,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
try
{
var queueItem = myQueueItem.ToString();
dynamic jsonData = JObject.Parse(queueItem);
string emailBody = jsonData.Content;
log.LogInformation("EmailBody: "+ emailBody);
sendGridMessage = new SendGridMessage
{
From = new EmailAddress("Orders@TimePilotCloud.com", "Order Updates"),
};
sendGridMessage.AddTo("xyz@zzzz.com");
sendGridMessage.SetSubject("Awesome Azure Function app");
sendGridMessage.AddContent("text/html", "Should Be Email Body");
}
catch (Exception ex)
{
sendGridMessage = new SendGridMessage();
log.LogError($"Error occured while processing QueueItem {myQueueItem} , Exception - {ex.InnerException}");
}
}
}
}