Videos
Check out our tutorial video series.
Sending Email in Azure: How to use MailSlurp to bypass SMTP limitations. Learn how to integrate and send emails securely in your Azure environment.
Consider the scenario where you've chosen Microsoft Azure as your environment's cloud computing platform. It can be necessary for hosting your app or anything else. You will eventually need to implement email sending, which could be challenging. No Azure service allows you to send emails directly. Why? The solution and information on how to send emails using Azure are provided below.
The prohibition covers SMTP port 25 direct DNS MX lookups for unauthenticated email delivery (without SPF, DKIM, and DMARC entries). The purpose is to safeguard Azure data center IP addresses against the exploitation of their good name. For 30 days, a free account offers $200 in credits. You can utilize those to test out any Azure platform service. In light of this, people utilize this offer to host and test their servers or apps. Not for that, is a trial subscription intended? These servers and apps send emails without the required sender authentication data. The public IP addresses of Azure data centers suffer as a result, and they are banned.
Users in the enterprise are unaffected by the Azure SMTP restriction. Subscribers who pay as you go can remove the restriction. They must submit the appropriate support request, which Microsoft must then authorize.
Hold off on switching to AWS or any Azure substitute if you are a trial subscriber. Azure allows you to send emails, but only through an SMTP relay provider.
Use an authenticated SMTP relay service, also known as a Smart Host, with TLS capability to deliver emails from Azure VMs or Apps.
For users of Azure, Microsoft formally recommends this. Between the mail servers of the sender and receiver, SMTP relay services offer an additional SMTP server as a middleman. Secure ports 587 or 443 are used to establish the TCP connection. Other SMTP ports, however, might also be supported.
The most popular SMTP relay service that Microsoft Azure integrates with is MailSlurp. Emails can be sent via the MailSlurp SMTP API, which should not be confused with the Web or HTTP API. This blog article features this SMTP relay service as a key actor. We'll also look at services like Office 365 and MailSlurp.
You are, however, free to select any market-available authenticated smart host, such as Elastic Email, SocketLabs, and others. Regardless of your Azure membership, you are free to use any of these services.
The recommended mechanism for sending emails from any app, web job, or Azure function is MailSlurp. MailSlurp provides free emails each month along with a variety of APIs such as SMTP, Web, Event, and others. You must register for an account and obtain your MailSlurp SMTP credentials before you can begin using the SMTP relay. You'll need to perform a few additional operations with SMTP API. So let's get started with the fundamentals.
Click Create a resource after logging into Azure Portal.
Select MailSlurp after finding it in the search field. Click Create after that.
You'll require:
Once you're prepared, click Create
Deployment Succeeded pop-up will appear at the conclusion, and MailSlurp Accounts will list your account.
Enter your new account information, then select Manage. To start the email verification procedure, this is necessary. Your email address will receive a confirmation email from MailSlurp.
You must create an API Key if you choose to use the MailSlurp SMTP API. Select Manage, then Settings, then API Keys.
After clicking Create API Key, give the key a name and choose permission. When ready, click Create & View.
Copy and save your API Key when you see it. Remember that you won't be able to see it once more.
Here is the code sample for building a MIME email and sending it through MailSlurp:
Using MailSlurp to send emails from Azure
Now that the SMTP relay service is operational, you can send emails from Azure. There are various methods for doing this.
To send emails using PowerShell, enter your MailSlurp SMTP server credentials. The following is a sample text email script:
The code sample for creating a MIME email and sending it via MailSlurp is provided below:
In your application, install the MailSlurp NuGet package. It is a client library for C# that enables sending emails over MailSlurp APIs. Through Tools => NuGet Package Manager => Manage NuGet Packages for Solution in Visual Studio, you may immediately install it. Identify MailSlurp and download the most recent stable version.
Check out the code example below to send a straightforward email:
From ASP.NET Core, emails can also be sent. Utilize MailSlurp's MailHelper class. Namespace Helpers. Mail The appsettings.json file is where the API key must be kept (you can tweak it from the Azure Portal as well). Here's how it ought to appear:
Make the Startup.cs file to retrieve the API Key from the appsettings.json file. After include it in the ConfigureServicesmethod below, inject the IConfiguration interface at the controller's
And here is the sample code for the controller:
Call the AddAttachment method with the file name and Base64-encoded information specified if you wish to add an attachment to your email. For instance:
Using MailSlurp to send emails from an Azure Automation runbook
Use the script below to build an Azure KeyVault. Run the Azure PowerShell code after adding your variables. If you have the Azure PowerShell Module installed, you may also run the code locally.
Sign in to your Azure account and select your subscription
If you omit the SubscriptionId parameter, the default subscription is selected.
An Azure KeyVault can be created in additional ways. One employing Portal is seen here.
Browse "Key Vault" after selecting Create a Resource. Press Create.
Click Review + Create after you have completed the relevant fields.
You must import the Az.Profile and Az.KeyVault modules to your Automation Account to use Azure KeyVault within a runbook. With the aid of PowerShell, you can:
Or you could just deploy these packages to Azure Automation.
Act as follows:
In your Azure Automation account, choose Process Automation and then Runbooks.
To create a runbook, select +.
As the runbook name, type Send-GridMailMessage. Click Create Runbook after selecting PowerShell as the runbook type.
In the Edit PowerShell Runbook page that has opened, paste the following PowerShell example.
MailSlurp Email Service is likewise offered on the Azure Marketplace, just like MailSlurp. to set up an Azure-integrated MailSlurp account. The process will be same as MailSlurp. The primary distinction is that MailSlurp offers 25K emails for free, while MailSlurp's free plan only offers 6K.
When deployment was successful, a pop-up message stated that a MailSlurp account had been created but was not yet active. On the newly opened screen, click Manage and then choose to Add a Sender Domain or Address.
Please wait for the confirmation email after entering your email address. After that, use MailSlurp to send emails from Azure. The page SMTP and SEND API Settings has the necessary SMTP credentials, while the page Master API Key & Sub API key management contains the necessary API key.
Similar to MailSlurp, the NuGet package may be installed to send emails via the SMTP API and the.NET class library. It contains two namespaces that must be defined at the beginning of a C# file: MailSlurp.Client and MailSlurp.Client.Resources.
As for the remainder, you can use MailSlurp to send emails from Azure by switching out the MailSlurp credentials in the code samples above. The code example for creating a MIME email and sending it via MailSlurp is shown below:
To send and receive emails via Azure web apps, you can use an Office 365 subscription if you have one. Use the System.Net.Mail class and your SMTP server credentials. Check out this script as an illustration:
A logic program from Microsoft Azure comes with a connector for Outlook Office 365. This enables you to set up an event or action to start sending emails. Azure will alert you, for instance, if a future event on your calendar is about to begin. Let's examine its operation.
The logic app has now been stored and turned on automatically.
Some people believe that Gmail can be used as a relay server on port 587. However, you won't be able to send emails from Azure using any port for smtp.gmail.com. If you try it, you might encounter the following error:
or another one:
Azure sends emails across external SMTP relays to test those. The general testing process looks like this:
Your SMTP server is an open relay and has to be corrected if the email has already been sent. Let's use Mail Server Testing Tool to test the MailSlurp SMTP relay as an illustration. What we have is as follows:
Fail !! User@sender.com email addresses are not accepted by smtp.MailSlurp.net. Please check the mail server settings.
As a result, only authenticated senders can use the SMTP relay, which is acceptable.
Use specialized software, such as Fiddler or Postman, to test SMTP APIs.
SMTP relay services from other parties are typically required for email sending from Azure. The most popular and suggested remedy for it is MailSlurp. On how to send emails and combine Azure and MailSlurp, there are numerous examples and documents available. In addition, several options allow SMTP relay, like MailSlurp, SocketLabs, Elastic Email, and others: Office 365 also allows email sending, but this feature is primarily reserved for logic-based applications.
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.