Question

Impossible to send emails from web service

Posted March 22, 2021 149 views
EmailPython

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.

edited by KFSys
1 comment

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.

×
Submit an Answer
1 answer

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

  • Thank you for the reply.

    Yes, I’m using this configuration to send emails:

    conf = ConnectionConfig(
        MAIL_USERNAME = my_email,
        MAIL_PASSWORD = my_pwd,
        MAIL_FROM = my_email,
        MAIL_PORT = 465,
        MAIL_SERVER = "smtps.aruba.it",
        MAIL_TLS = False,
        MAIL_SSL = True,
        USE_CREDENTIALS = True
    )
    

    As I said, from my local PC everything works fine, so the password is correct.

    The number of the opened ticket is #4611432.

    Thank you for the support.

    Best regards,
    Mattia