In this blog post, we will demonstrate how to acquire a SendGrid API key on Microsoft Azure. SendGrid is a widely used email delivery service in the cloud that offers dependable transactional email delivery, scalability, and real-time analytics, along with versatile APIs to facilitate smooth custom integration.
Step 1: Create a SendGrid Account
The first step is to create a SendGrid account. Visit the SendGrid website and follow the sign-up process.
Step 2: Creating a SendGrid Resource in Azure
Once you have an account, you can create a SendGrid resource in Azure. Sign in to the Azure portal and search for ‘SendGrid Email Delivery’ in the marketplace. Make sure to fill out all the necessary information and create the resource.
Step 3: Retrieve the API Key
After your SendGrid resource is successfully created, proceed to the ‘Manage’ button which will redirect you to the SendGrid dashboard. Here, navigate to ‘Settings’ and then to ‘API Keys’. Click on ‘Create API Key’.
Give your API key a suitable name and select the permissions you need it to have. For full access, choose ‘Full Access’. After this, click on ‘Create & View’.
Your API key will be generated and shown only once. Make sure to copy it and keep it safe. If you lose it, you’ll need to create a new one.
So, in your code, you can use the SendGrid API key like this:
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: '<strong>and easy to do anywhere, even with Node.js</strong>', }; sgMail.send(msg);
And that’s it! Now you know how to get your SendGrid API key in Azure. Remember to replace process.env.SENDGRID_API_KEY with your actual SendGrid API key.