diff --git a/packages/client/USE_CASES.md b/packages/client/USE_CASES.md index bd47e07df..e45ac562b 100644 --- a/packages/client/USE_CASES.md +++ b/packages/client/USE_CASES.md @@ -18,4 +18,4 @@ Find more information about all of SendGrid's whitelabeling related documentatio You can find documentation for how to view your email statistics via the UI [here](https://app.sendgrid.com/statistics) and via API [here](https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/client/USAGE.md#stats). -Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as SendGrid processes your email. \ No newline at end of file +Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as SendGrid processes your email. diff --git a/packages/mail/USE_CASES.md b/packages/mail/USE_CASES.md index 2b697a6df..055eb6189 100644 --- a/packages/mail/USE_CASES.md +++ b/packages/mail/USE_CASES.md @@ -19,6 +19,7 @@ This documentation provides examples for specific email use cases. Please [open * [Kitchen Sink - an example with all settings used](#kitchen-sink) * [Deploy a Simple App on Google App Engine with Node.js](#gae) * [Deploy a Simple App on Heroku with Node.js](#heroku) +* [How to Setup Email Sending on Azure](#send_via_azure) * [How to Setup a Domain Whitelabel](#domain-white-label) * [How to View Email Statistics](#email-stats) @@ -580,6 +581,39 @@ Here are step by step instructions to deploy your Node.js app to Heroku (assumin - `heroku config:set SENDGRID_API_KEY=SG.YOUR.OWN-API_KEY-HERE` (replace `SG.YOUR.OWN-API_KEY-HERE` with your own [api key from sendgrid](https://app.sendgrid.com/settings/api_keys) If you run into any other non SendGrid related issues, don't forget to read through [Heroku's deployment documentation](https://devcenter.heroku.com/articles/getting-started-with-nodejs). + + +# How to Setup Email Sending on Azure + +1. First create a account on azure. You can opt for free trial here or buy a subscription. +2. I am assuming you already have sendgrid API Key with you. +3. Create a sample node.js App. with an index.js and create a package.json file using npm init or yarn init. +4. Install sendgrid-nodejs as a dependency using yarn add @sendgrid/mail. +5. Now we need the SendGrid API key to be as an Environment Variable in our application. For that we will create an sendgrid.env file in our local system. Add it to .gitignore file and refresh the terminal. +```shell +echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env +echo "sendgrid.env" >> .gitignore +source ./sendgrid.env +``` +6. Now lets go to our index.js file and copy paste the following code. +```js +const sgMail = require('@sendgrid/mail'); +sgMail.setApiKey(process.env.SENDGRID_API_KEY); +const msg = { + to: 'test@example.com', + from: 'test@example.com', + subject: 'Sending with SendGrid is Fun', + text: 'and easy to do anywhere, even with Node.js', + html: 'and easy to do anywhere, even with Node.js', +}; +sgMail.send(msg); +``` + +This will enable you to send a simple message to be sent to your email. +7. If you have followed all steps till here. Your app should work fine in local. Now it's time to deploy in Azure. +8. Follow the guide on [depolying to azure](https://docs.microsoft.com/en-us/azure/app-service/app-service-deploy-local-git) to the word. It might seem a little difficult to navigate with so many options but once you crack it, It will be a cakewalk. +9. Now as soon as you will deploy your application. It will run on the aforementioned port. You will again receive a message in your inbox. +10. And Voila you have your app deployed and sending Emails via Azure. Now you can chain your custome logic if you need to send emails as per some parameters and to specific people as per your requirement. # How to Setup a Domain Whitelabel