Question

Impossible to send emails from web service

Hello, I’m having trouble sending emails from my Python web service which runs on a Digital Ocean droplet (ubuntu 20.04). More specifically, I’m using the fastapi-mail library for sending emails, and I get the following error:

aiosmtplib.errors.SMTPServerDisconnected: Connection lost

The strange thing is that the same code works fine from my local machine, but it continuously fails from the Digital Ocean droplet. Do you have any suggestions?

Thanks in advance.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @campanamattia,

When configuring, you’ll need to add the following configuration in your conf file


conf = ConnectionConfig(
    MAIL_USERNAME = "YourUsername",
    MAIL_PASSWORD = "strong_password",
    MAIL_FROM = "your@email.com",
    MAIL_PORT = 587,
    MAIL_SERVER = "your mail server",
    MAIL_TLS = True,
    MAIL_SSL = False,
    USE_CREDENTIALS = True
)

Can you confirm you have added an actual Mailbox,password? Additionally, I’ll recommend using TLS,SSL and Credentials while port shouldn’t be 25 but 465 or 587.

Additionally, what you’ve found (the question you posted) is true so that might fix your issue as well!

If you provide me with a ticket number, I can try and escalate it from the community.

Regards, KFSys