You'll need to set up email sending after choosing Microsoft Azure services as the cloud computing platform for your environment. Since Azure's SMTP restrictions prevent direct email sending to external domains, the process is complicated.

To get around these restrictions when sending emails from Azure, you must learn various techniques for sending emails with Azure. Keep reading to learn different ways of getting this done.

How to Send Emails From Azure with Azure Communication Service

Users can now send bulk emails directly from their app using the "Azure Communication Service Email." It works with C#, JavaScript, Java, and Python, four ready-made software development kits (SDKs). And before you can start sending emails from Azure, you must create an Email Communication Service resource.

To kick-start, follow the steps below.

  • Go to the Azure Portal first, then sign in with your account.
  • Select the "Create a resource" button on the Azure services tab.
  • Enter "Email Communication Services" in the search box, open the page, and click "create."
  • Complete the required fields in the basics tab, add tags if desired, and click "Review + create."
  • If the validation is unsuccessful, wait for it to finish before making any corrections. Select "Create" if you pass the validation test.
  • Click "Go to resource" when the deployment completes.

Note: You can either create a custom domain or add an Azure subdomain. Pick a custom domain if you plan to use email communication services for business. Connect the domain to the Azure Communication Service resource after validating it.

Connecting the Azure Communication Service Resource

To begin the process,

  • Follow the Email Communication Service's process to create an Azure Communication Service resource.
  • Select a subscription, resource group, email provider, and the verified domain you want to connect before pressing "Connect domain" to filter the results.
  • The connected domain will appear after you click "Connect."

Sending emails from Azure

If the domain verification is successful, you can use the C#, JavaScript, Java, or Python SDKs to integrate Azure to send emails. These programming languages follow a similar pattern, and today we'll show you this with some C# code samples.

You'll need the most recent.NET client library to send emails from Azure using C#. Run the dotnet command to see if the library is set up. If it is up to date, use the dotnet command to create a new app and give it the name EmailQuickStart:

Use the dotnet build command to then begin building the new app:

Installing the Azure Communication Service Email library comes next. The dotnet add package command is used to accomplish this:

Once the package has been installed, use the following code sample to specify the project's starting point:

It's crucial to authenticate EmailClient before sending emails.

Use the connection string to authenticate that you can find in the communication service resource in the Azure portal. It's under the "Keys" tab. Set the key as an environment variable (like ) so that you can read it in code.

Use the code below to authenticate with Azure AD after installing the Azure.Identity library package:

With the help of the following code sample, you can send a basic email by changing the email addresses and personalizing the message and subject:

When entering the var sender parameter, make sure to use an email address with a verified domain.

By retrieving the MessageId from the response, as shown in the code sample above, it is possible to monitor the deliveryWith GetSendStatus, and obtain the message's status. tSendStatus.

You can send emails to multiple recipients using Azure Email Communication Service. Simply add the To, CC, and BCC recipients to the object:

Why is Using a Third-party SMTP Service for Email Sending Preferable?

Because Azure Communication Service Email is still being evaluated, it is preferable to use the SMTP service to send emails. Again, there are volume restrictions on Azure email, and users can send the following:

  • 10 emails per minute

  • 25 per hour

  • 100 per day

Last but not least, Microsoft has prohibited outbound SMTP communication from Azure since November 5, 2017, to safeguard Azure data center IP addresses from misuse.

With the MailSlurp Email API, senders can automate email delivery and ensure that messages arrive in recipients' inboxes. You can easily send bulk emails using Email API; you also have access to deliverability alerts, actionable analytics, and 60 days' worth of email logs.

Whether you use the API or SMTP, you'll need a MailSlurp account to start and complete the process.

  • Visit mailslurp.com and click "Sign Up"

  • Click the link in the verification email sent to you to confirm your email address

  • Log into your MailSlurp account after your email has been verified.

  • In the left navigation panel, select "Inboxes" and then "Domains."

  • Follow these steps to add and verify your domain, then find code examples and SMTP credentials, and click the "API and SMTP" tab.

  • Choose SMTP or API integration, then adhere to the guidelines.

Using MailSlurp Email SMTP to Send Emails From Azure

If you want to integrate MailSlurp with SMTP credentials in your application, use the SMTP client library for your choice of programming language. Run the following command to include the Nodemailer library in your Azure project:

You must create a new transporter object and import the library. Enter the credentials, which should include the host, port, username, and password.

Sending Emails with MailSlurp Email SMTP Using Azure Logic Apps

To begin, you must first create a new Logic App.

  • In the search bar of your Azure portal, type Logic App; Click "Add."

  • Fill in the blank fields.

  • Select "Review + create," then wait as the deployment completes. Select "Go to resource" and then "Logic app designer" from the menu that appears. Choose the "Blank Logic App template" to create a new project.

  • Set up a trigger that will result in an SMTP action.

  • In the search box, select "New step" and enter "SMTP." press "Send Email" after selecting "SMTP";

  • Navigate to your MailSlurp Email API account, and steer to the ‘API and SMTP’ tab to copy your SMTP credentials.

  • When you get back to the Azure Logic App, use the copied SMTP credentials to fill in the blanks. Be sure to use the username and password listed in the SMTP tab of your MailSlurp account. - Click "Create" and then "Add parameter" to start; choose every parameter you wish to send in your email;

  • Create an email by indicating the From, To, Subject, and Body fields;

  • Save the logic app before you start sending emails in response to the selected trigger.

  • To integrate MailSlurp Email SMTP with Azure, use Microsoft PowerShell and the Send-MailMessage command.

  • Use the Send-MailMessage cmdlet to compose an email by starting a new PowerShell session.

  • Copy the SMTP server login information for MailSlurp. The SmtpCredentials parameter should contain your MailSlurp username and password as well as the host (mailslurp.mx):

Here is a powershell example:

Send Emails With Azure Function App and MailSlurp Email API

Using the MailSlurp Email API and Azure Function App, you can send emails from Azure. Let's configure the system.

  • Enter "Function App" in the search bar of the Azure portal, then open Function App and click "Create."
  • Complete all of the tabs' fields with information, then select "Review + Create"; Press "Go to resource" after the deployment is finished, then use the left panel to select the "Functions" tab. Press ‘Create’
  • Select the "HTTP trigger" under the templates section after choosing the development environment. Name the trigger and select the level of authorization.
  • You can now launch your Function App by clicking "Create."

If you use the Azure portal as your development environment, go to the "Code+test" tab to create and test your HTTP trigger. Otherwise, you can continue editing.

Here is an example of code that uses the MailSlurp Email API to create an HTTP trigger and send emails.

  • Replace your_api_key with the actual MailSlurp API key and your_http_trigger_url with the URL of the HTTP trigger, along with the correct values for the email addresses, subject, and body.

The MailSlurp Email API works similarly to SMTP with Azure Logic Apps.

  • Following the instructions we provided above, create a new Logic App and choose the "Blank Logic App" template.
  • Utilize the search bar to locate the "When an HTTP request is received" trigger. This trigger will start your Logic App when the MailSlurp API detects a request to send an email.
  • Press "Use Sample Payload to generate schema" or enter the schema manually; select "New Step."
  • Include an "HTTP" action. So when you want to send the email, this action will make an HTTP request to the MailSlurp API. In the ‘URI’ field, enter the URL of the MailSlurp API endpoint for sending emails (https://send.api.mailslurp.com/api/send).
  • Add two headers to the HTTP action's "Headers" section: "Content-Type" with the value "application/json" and "Api-Token" with the MailSlurp API token associated with your account.
  • Enter the JSON payload for the email in the HTTP action's "Body" section. In addition to any other email properties, you want to set up, including the recipient, subject, and body of the email.
  • Make an HTTP request to the trigger URL when you're ready to test your Logic App. By doing this, the email will be delivered to the recipient's inbox using the MailSlurp API.

Send emails from Azure with Office 365

To begin, you need to be subscribed to Office 365 to send and receive emails from Azure Web Apps. To use the system, you must enter the credentials for your SMTP server.

Office 365 Outlook connector

Azure logic app from Microsoft Azure comes with a connector for Outlook Office 365. As we did before, first create a logic app, then use the search box to look through Office 365 and choose it.

Decide on a trigger and an action. Consider this:

  • Action: Dispatch an email.
  • Trigger: Whenever a future event is about to begin.

You'll be given the option to log into Office 365. There is now a connection. Let's now adjust the action as well as the trigger:

The Trigger

Change the frequency and interval after selecting a calendar from the drop-down menu. To give you an example, let's say we need to start the action (send an email) 10 minutes before the event is set to start: Set Minute as the Frequency and 15 as the Interval. Save any changes you make.

The Action

  • Include the Send email action, change variables, then save your changes.

Your logic application should now be running and saved if everything goes smoothly and without any errors.

How to test emails before sending them from Azure

Before sending emails to recipients, you must test them to ensure they are error-free.

The Email Sandbox allows you to analyze emails for spam and blacklists, validate HTML/CSS, test Bcc email headers, view emails in raw and text formats, and more.

You can send test emails to your inbox directly from your Azure project or use an SMTP integration to integrate MailSlurp Email Sandbox with your app.

  • Log into your MailSlurp account and select the "Sandbox" tab; navigate to your inbox.
  • Activate the 'SMTP Settings tab to access the API integrations for various programming languages.
  • The drop-down menu will allow you to select the language that your Azure app is using.

Note: From the "SMTP Settings" tab, choose "Show Credentials" to integrate SMTP. You can send emails from your email client by copying the credentials.

Copy the email address that appears when you click the "Email Address" tab to send emails directly to MailSlurp's inbox.

Conclusion

Azure supports sending emails using a variety of techniques. This article covered techniques utilizing Outlook connectors and the Azure Email Communication Service. Before sending emails to recipients, remember to test them in the MailSlurp Email Sandbox.