简体   繁体   中英

Send mail with smtplib works when deployed in local but fails when deployed in swarm (Cannot assign requested address)

We have a container with a python flask service that listens in the port 5000. We need to be able to send notification emails from that container to smtp.office365.com to the port 587.

This container, when deployed in a local machine works perfectly, but when deployed in a swarm server the following error code is returned: [Errno 99] Cannot assign requested address

From the information I've found, I'm guessing there is a problem with the configuration of the outgoing connection when sending the email, but I'm still not sure about what extra configuration does the container need for sending the email when deployed in a swarm when compared to deploying in local.

In the dockerfile, only the 5000 port is exposed and binded to the flask server.

When sending the email with smtplib, only the port of the smtp server is required to be specified (587 in my case).

What could I be missing? Do I need to expose new ports for this? Could be a problem with binding to localhost? I don't have a clear picture of the path the mail follows since it's sent from my python code until it arrives to the smtp server.

Got the same issue but while using docker-compose. Worked after I opened port "587" using compose

- ports
  - "587:587"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM