Use of SendGrid
SendGrid is used to deliver your transactional and business emails through Cloud system. It also will deliver a thousand of email in a minute. The SendGrid has a attachment option to send any document with email.
Step 1
Open the Windows azure account with your credential. Go to Search box in top of the page and Search Send Grid in search box.
Step 2
It will redirect into a new page called Send Grid Account.
There you can Add new SendGrid Account.
Step 3
Enter the information on required fields. As you can see the Name, Password, Confirm Password and Other required fields.
If you are paid user, then click the “Paid-as-go” option in subscription dropdown box.
Resource Group: It means location. We should create a new resource group to create a new SendGrid.
Step 4
Select the pricing tire. It will send an email based on setting Pricing Tier.
Step 5
We selected “Free” account. We have three options in Pricing Tire,
Each type has different type of usage as you can see in the below screenshot.
Step 6
Click on Contact Information and fill out the required fields on the page. This will verify your “To Address”.
Main purpose of this information is that where the email is come from and name of the person/organization.
Enter the required information on Contact Information.
Step 7
Read the legal terms and click and then confirm the check box and click on Create button.
Complete the process then click on Create button.
Step 8
The deployment process will take some time to finish.
Step 9
Refresh the account.
Step 10
Click on Manage to see more details about created SendGrid.
Step 11
The SendGrid will send you the confirmation mail to respective email address to authorize.
Click on Send Confirmation Email and check your personal email account.
Step 12
After the confirmation, it will redirect to Key settings page. Click on Settings and go to API Keys on left menu bar.
Copy the API key by following the steps.
Click on Create API key button and you will see the key on the window.
.NET Code development
Use the following steps for dot net implementation. I have pasted the copied key on my app config file.
Copy the whole working code and paste on your project.
- "Key": {
- "FromAddress": "[email protected]",
- "SubjectName": "Mail from Azure and SendGrid",
- "AzureSendGridKey": "SG.x4W9xmHzRueW7RuEwdeQnw._lyBezACbfJmqLsM1lbQB………<<my key>>"
- }
Step 14
Write the code inside your API.
- public async Task SendEmailAsync(string ToAddress, string subject, string messages)
- {
- string fromAddress = Configuration["Key:FromAddress"];
- string SubjectName = Configuration["Key:SubjectName"];
- string AzureSendGridKey = Configuration["Key:AzureSendGridKey"];
- var client = new SendGridClient(AzureSendGridKey);
- var msg = new SendGridMessage();
-
- msg.SetFrom(new EmailAddress(fromAddress, SubjectName));
-
- var recipients = new List<EmailAddress>
- {
- new EmailAddress(ToAddress)
- };
- msg.AddTos(recipients);
-
- msg.SetSubject(subject);
-
-
- msg.AddContent(MimeType.Html, messages);
- var response = await client.SendEmailAsync(msg);
- }
Build the application and run it.
Step 15
You will get the notification email like the below.
Happy coding…