The following forum(s) have migrated to Microsoft Q&A (Preview): Azure App Service - Web Apps, Azure App Service - Web Apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

Webjob, Sendgrid, not working on Azure RRS feed

  • Question

  • We have developed a webjob (console program, C#) that must send email using SendGrid.
    When we run the job in our development environment (local server) sending email works fine.

    But, when we run the job on Azure, sending email does not work - the webjob status on Azure says 'Success' but no emails pops up on the SendGrid portal (Activity page).

    How can we debug the webjob to get an idea of the cause?

    Wednesday, January 13, 2016 2:15 PM

All replies

  • Are you using the Webjobs SDK and the SendGrid Extension?
    Wednesday, January 13, 2016 3:51 PM
  • Do you see any errors in your job output? You can access the logs via the portal as described in "View the Job History" this document.

    Recommend adding error handling around your SendGrid operations to ensure that those email operations are successful. Also make sure your SendGrid ApiKey is correctly specified in app settings or via the portal settings. It might be that your send operations are failing. Write some log entries at various stages of sending to see where things are failing.

    Mathew Charles [MSFT]

    Wednesday, January 13, 2016 4:35 PM
  • Hi,

    I can see (Manage NuGet Packages) that Sendgrid 6.3.4 and SendGrid.SmtpApi 1.3.1 is installed.

    Thursday, January 14, 2016 7:26 AM
  • Hi,

    1) we already have lots of debugging info displayed (Console.Write) - no errors reported
    2) we ARE using "View the job history" - no errors reported
    3) our 'send mail statement' is already wrapped in a Try..Catch-block - no errors reported
    4) we are pretty sure that the key to SendGrid is correct - remember that the program sends emails, when it is executed in our development environment (on-site server).

    Thursday, January 14, 2016 7:37 AM
  • Hi,

    Found the following in this article :

    // If developing a Console Application, use the following
    // transportWeb.DeliverAsync(mail).Wait();

    We added ".Wait" and now emails are sent, also when the program is executed on Azure.

    But why is this required?

    Thursday, January 14, 2016 11:02 AM
  • Ahhh, you weren't waiting for the async Tasks to complete! What was happening was you were starting the async send operations but you weren't waiting for them to complete. Therefore your WebJob console app would terminate before the mail was actually sent. I've seen this async issue bite others before.

    If the SendGrid API has a non-async version and the rest of your code is non-async, you might use that instead to obviate the need for the .Wait().

    Mathew Charles [MSFT]

    Thursday, January 14, 2016 4:47 PM
  • If you are using Webjobs, I recommend using the Webjobs SDK and the SendGrid Extension, it makes things as easy as declaring a function like this:

    public static void ProcessOrder(
        [QueueTrigger(@"samples-orders")] Order order,
            To = "{CustomerEmail}",
            Subject = "Thanks for your order (#{OrderId})!",
            Text = "{CustomerName}, we've received your order ({OrderId})!")]
        SendGridMessage message)
        // You can set additional message properties here

    It automatically does all the magic of contacting to SendGrid and making sure it gets received, you just make sure that you pair it with a Trigger (Queue Message, Timing, etc.).

    More examples here.

    Friday, January 15, 2016 12:31 PM
  • Hi buddy, here I have the pretty much same problem, I'm using the wait calling


    But messages are not being delivered, is there anything else that must be setting on Azure?

    Tuesday, December 20, 2016 9:31 PM