Report this

What is the reason for this report?

Impossible to send emails from web service

Posted on March 22, 2021

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.



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!

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.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.