How to open ports / sendmail from Linux App Service (Container)? or; Use Outlook o365 as SMTP service

Herbert Kimani 66 Reputation points
2023-07-08T10:34:17.4566667+00:00

How can one send emails from code using local (in the container) SMTP server i.e. Postfix. How to map appsvc ports to container port 25 or 587. **Setting the WEBSITES_PORT env var on the portal doesn't work and some sources say outbound is only possible on http and https ports (which would be ridiculous) but yet the ssh port works with Kudu.

**Not on a vnet and have no spare email account to use external SMTP server so if the only solution then is to use a service. How can I use outlook365 but without authenticating with my work credentials in the code? Preferably using a shared mailbox associated with my account and may be a key for auth instead of authenticating with my work credentials.

Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,960 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sedat SALMAN 14,180 Reputation points MVP
    2023-07-08T10:49:57.3933333+00:00

    Azure App Service provides a fully managed, platform as a service hosting solution (https://learn.microsoft.com/en-us/azure/developer/intro/hosting-apps-on-azure). It is designed to be a secure environment, and to prevent spam, most cloud service providers, including Azure, have blocked outbound connections on the SMTP ports.

    There are email service providers that allow sending emails through their API, and these should work fine within Azure App Services, as HTTP and HTTPS ports are open for outbound connections. Services like SendGrid, Mailgun, or Mailjet provide APIs for sending email.

    Or you can use System.Net.Mail.SmtpClient or similar library to send email using an external provider

    0 comments No comments

  2. VenkateshDodda-MSFT 25,111 Reputation points Microsoft Employee Moderator
    2023-07-10T06:47:46.34+00:00

    @Herbert Kimani Thanks for reaching out to Microsoft Q&A.

    We noticed your feedback that the above answer was not helpful, thank you for taking time to share feedback.

    Based on the shared information, I have understood that you are trying to open ports 25 and 587 on Linux app service to implement email mechanism in your application.

    Also, the app setting WEBSITES_PORT is used to bind/run your application container( to recieve/route the requests to your application) on that port. for more information refer to the different application settings in app service here.

    As mentioned in this documentation, you can use port 25 for outbound communication but sending an email using that port is unsupported across all the PAAS services.

    Please check this for Recommended method of sending an email through Azure App service.

    If the provided information is helpful, request you to take a resurvey.

    Looking forward to your reply. Much appreciate your feedback.


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.