flask-mail icon indicating copy to clipboard operation
flask-mail copied to clipboard

Alternatives?

Open OneAdder opened this issue 6 years ago • 7 comments

I really need something to send emails with Flask and I really don't want to program it from scratch. This package doesn't seem to be maintained. Are there any other options?

OneAdder avatar Apr 10 '19 23:04 OneAdder

Yes, copy the email implementation from Django; its dependencies on other Django stuff are basically non-existent, and as far as I know it's the best mail sending implementation that's available for python (and it handles all the nasty corner cases like when non-ascii stuff is involved).

Actually, I did exactly this for the project I'm working on about two years ago. Feel free to copy from there (but I'd check if Django fixed anything since then); it'll be even less effort than copying it from Django yourself since the external dependencies in my version are even smaller.

ThiefMaster avatar Apr 22 '19 14:04 ThiefMaster

Cool, thank you!

OneAdder avatar Apr 30 '19 14:04 OneAdder

@OneAdder You can check out the inbuilt email package in the standard library.

michaelbukachi avatar Nov 13 '19 09:11 michaelbukachi

Yes, copy the email implementation from Django

This is what https://github.com/waynerv/flask-mailman do.

bersace avatar Apr 27 '20 07:04 bersace

You can do this right within the standard library:

import smtplib
import ssl
from email.mime.text import MIMEText

sender = '[email protected]'
the_email_password = 'P@s5w0|^\D'
destination = '[email protected]'

def email_user(sender, the_email_password, destination):
    mail_body = 'lorem ipsum'
    email_sender = sender
    email_cipher = 'ECDHE-RSA-AES256-GCM-SHA384'
    email_server = 'smtp_server'
    email_port = 465
    # https://support.office.com/en-us/article/Outlook-com-no-longer-supports-AUTH-PLAIN-authentication-07f7d5e9-1697-465f-84d2-4513d4ff0145
    # https://en.wikipedia.org/wiki/SMTP_Authentication#Details
    email_auth = 'LOGIN'
    email_password = the_email_password
    email_destination = destination
    subject = 'subject'
    msg = MIMEText(mail_body, 'plain')
    msg['Subject'] = subject
    msg['From'] = email_sender
    ssl_context = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)
    ssl_context.verify_mode = ssl.CERT_REQUIRED
    ssl_context.check_hostname = True
    ssl_context.set_ciphers(email_cipher)
    ssl_context.options |= ssl.HAS_SNI
    ssl_context.options |= ssl.OP_NO_COMPRESSION
    # No need to explicitally disable SSLv* as it's already been done
    # https://docs.python.org/3/library/ssl.html#id7
    # The below options are done so as to force TLS1.2
    ssl_context.options |= ssl.OP_NO_TLSv1
    ssl_context.options |= ssl.OP_NO_TLSv1_1
    ssl_context.options |= ssl.OP_SINGLE_DH_USE
    ssl_context.options |= ssl.OP_SINGLE_ECDH_USE
    conn = smtplib.SMTP_SSL(email_server, port=email_port,
                            context=ssl_context)
    conn.esmtp_features['auth'] = email_auth
    conn.login(email_sender, email_password)
    try:
        conn.sendmail(email_sender, email_destination, msg.as_string())
    finally:
        conn.quit()

Lvl4Sword avatar May 28 '20 02:05 Lvl4Sword

@Lvl4Sword except that this won't handle all the ugly edge cases there are when it comes to emails.

ThiefMaster avatar May 28 '20 07:05 ThiefMaster

I don't believe it does either, as it was something I provided as a simple example which should work for most basic usecases.

Lvl4Sword avatar May 28 '20 07:05 Lvl4Sword

A group of us have been working to reactivate this project, which has now moved to the pallets-eco organization. Closing this, not making any statements about the merits of continuing to use flask-mail vs. switching to an alternative (people should use what makes them happy)

wlach avatar May 20 '24 22:05 wlach

Flask-Mail is now part of the Pallets Community Ecosystem. Pallets is the open source organization that maintains Flask; Pallets-Eco enables community maintenance of Flask extensions. If you are interested in helping maintain this project, please reach out on the Pallets Discord server.

davidism avatar May 23 '24 15:05 davidism