How to fix smtp relay issue on azure VM?

Sherwin Dcosta 0 Reputation points
2023-09-03T17:41:27.83+00:00

I am facing the error Connection could not be established with host diggibyte-com.mail.protection.outlook.com :stream_socket_client(): Unable to connect to diggibyte-com.mail.protection.outlook.com:25 (Connection timed out) following the instructions at https://learn.microsoft.com/en-us/azure/virtual-network/troubleshoot-outbound-smtp-connectivity#recommended-method-of-sending-email I can send email from my local machine, but when I deploy it in an Azure VM, I get this issue. In the virtual machine, I have ports 25 inbound and outbound open. and also I am using office 365 smtp relay

Microsoft 365 and Office | Office Online Server
Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,775 questions
Exchange | Exchange Server | Management
{count} votes

1 answer

Sort by: Most helpful
  1. GitaraniSharma-MSFT 50,096 Reputation points Microsoft Employee Moderator
    2023-09-12T06:08:37.93+00:00

    Hello @Anonymous ,

    I understand that you are unable to send email from your Azure VM and getting Connection timed out error, even though you've opened port 25 (inbound and outbound) and are using office 365 smtp relay service. Your subscription type is Pay-as-you-go.

    I see that you have already referred to the below article, however, I would like to draw your attention to some important points here.

    https://learn.microsoft.com/en-us/azure/virtual-network/troubleshoot-outbound-smtp-connectivity

    It is possible to use port 25 for outbound communication on Azure VMs, but there are some subscription limitations which are described below:

    • For VMs that are deployed in standard Enterprise Agreement subscriptions, the outbound SMTP connections on TCP port 25 will not be blocked.
    • For Enterprise Dev/Test subscriptions, port 25 is blocked by default. It is possible to have this block removed.
    • For all other subscription types, the Azure platform will block outbound SMTP connections on TCP port 25 for deployed VMs and this block cannot be removed. This includes Pay-as-you-go.

    So, when using a non-enterprise subscription type, users are encouraged to use an authenticated SMTP relay service to send email from Azure VMs through TCP port 587, or other ports (as port 25 is blocked by default and this block cannot be removed).

    I see you've mentioned that you are using Office 365 SMTP relay, but you are still using port 25 which is blocked by Azure for Pay-as-you-go subscription. So, even though you use a SMTP relay service, with the port 25 being blocked for your subscription, you will not be able to send emails. You need to use a different port from the Azure VM.

    I checked and found that Port 25 is required for Microsoft 365 or Office 365 SMTP relay, so using this service may not work for your subscription.

    https://learn.microsoft.com/en-us/exchange/mail-flow-best-practices/how-to-set-up-a-multifunction-device-or-application-to-send-email-using-microsoft-365-or-office-365#requirements-for-microsoft-365-or-office-365-smtp-relay

    You can explore other authenticated SMTP relay service which supports port 587.

    SendGrid is one such SMTP relay service, but there are others. You might also have an authenticated SMTP relay service on your on-premises servers.

    SendGrid accepts unencrypted and TLS connections on ports 25, 587, & 2525. You can also connect via SSL on port 465.

    Refer: https://docs.sendgrid.com/for-developers/sending-email/getting-started-smtp#send-an-smtp-email-using-telnet

    Kindly let us know if the above helps or you need further assistance on this issue.


    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.