
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.
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.
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.