none
[Node.js][Mobile Apps] cc of SendGrid not working in Azure Mobile app RRS feed

  • Question

  • I have been trying to use the cc option of SendGrid in Azure Mobile app but it seems that email address set in cc field is ignored. How do we send cc using SendGrid in Azure Mobile app having JavaScript back end? It seems PHP code had this issue as well but was fixed long time back as mentioned here https://github.com/sendgrid/sendgrid-php/issues/83 

    Also, if we create the Email object first, calls its AddCc method and then pass it to SendGrid.send, it throws exception. Only the below syntax seems to work in the Azure Mobile app as explained here https://azure.microsoft.com/en-us/documentation/articles/store-sendgrid-mobile-services-send-email-scripts/#comment-2539027195

    sendgrid.send({
          to: '**email-address**',
          from: '**from-address**',
          subject: 'New to-do item',
          text: 'A new to-do was added: ' + item.text
       }, function(success, message) {
          if (!success) {
          console.error(message);
       }
    });

    As can be seen above, the callback function has success parameter passed in whereas the node.js module in GitHub (https://github.com/sendgrid/sendgrid-nodejs) has error parameter instead. So it seems Azure mobile service is not using the same module or version, there is some disconnect there as well.

    sendgrid.send(email, function(err, message) {
       if (err) {
          console.error(message);
       }
    });



    Saturday, February 27, 2016 10:44 AM

Answers

  • As the default version of SendGrid in Mobile Service is "0.2.4" which is much lower than the latest one.

    there are 2 approaches you can follow to try to update the version of sendgrid in mobile service:

    1, Sign in the kudu console site of your mobile service, leverage the cmdlet online on the site to modify the "package.json" file of your mobile service application, e.g.:

    "sendgrid":"^2.0.0",

    under the "dependencies" closure. Then run command : "npm update" in the cmdlet to update the sendgrid sdk in mobile service. The Kudu console site URL should be "https://<your_mobile_service_name>.scm.azure-mobile.net/DebugConsole"

    2, You can refer to https://azure.microsoft.com/en-us/documentation/articles/mobile-services-store-scripts-source-control/#use-npm to deploy the sendgrid sdk for your own, and use 

    var sendgrid  = require('sendgrid')('YOUR_SENDGRID_API_KEY');
    in your code to implement sendgrid. 

    Any further concern, please feel free to let me know.

    Monday, February 29, 2016 2:30 AM
    Moderator