简体   繁体   中英

After updating flask-mail not sending emails

My website started erroring 404; email confirmation wasn't functioning. I believe due to changes to Google security. I updated all packages and Python. I setup Google 2-step verification and created the app password. I don't get errors but from send_email I don't receive email. I successfully pinged smtp.gmail.com. There's been changes to Flask and Google security so please don't link outdated post.

email.py:

from flask_mail import Message
from GetMowed2 import app, mail

def send_email(to, subject, template):
    msg = Message(
        subject,
        recipients=[to],
        html=template,
        sender=app.config['MAIL_DEFAULT_SENDER']
    )
    mail.send(msg)

init .py:

from flask_mail import Mail, Message
import json

app = Flask(__name__)

# from GetMowed2 import app as application

#with open('/etc/config.json') as config_file:
#  config = json.load(config_file)

app.config.from_file("/etc/config.json", load=json.load)

# Magic that creates everything, including Base (db.Model), engine (db.engine), and session >
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///Mowed2.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = 'SQLALCHEMY_TRACK_MODIFICATIONS'
app.config['SECRET_KEY'] = 'SECRET_KEY'
app.config['SECURITY_PASSWORD_SALT'] = 'SECURITY_PASSWORD_SALT'

# mail settings
app.config['MAIL_SERVER']= 'MAIL_SERVER'
app.config['MAIL_PORT'] = 'MAIL_PORT'
app.config['MAIL_USE_TLS'] = 'MAIL_USE_TLS'
app.config['MAIL_USE_SSL'] = 'MAIL_USE_SSL'
app.config['TESTING'] = 'TESTING'
app.config['MAIL_SUPPRESS_SEND'] = 'MAIL_SUPPRESS_SEND'
app.config['MAIL_FAIL_SILENTLY'] = 'MAIL_FAIL_SILENTLY'

# gmail authentication
app.config['MAIL_USERNAME'] = 'MAIL_USERNAME'
app.config['MAIL_PASSWORD'] = 'MAIL_PASSWORD'

# mail accounts
app.config['MAIL_DEFAULT_SENDER'] = 'MAIL_DEFAULT_SENDER'
mail = Mail(app)

config.json:

{
    "SQLALCHEMY_TRACK_MODIFICATIONS": false,
    "SECRET_KEY": "*******",
    "SECURITY_PASSWORD_SALT": "******",

    "MAIL_SERVER": "smtp.gmail.com",
    "MAIL_PORT": 465,
    "MAIL_USE_TLS": false,
    "MAIL_USE_SSL": true,
    "MAIL_SUPPRESS_SEND": false,
    "MAIL_FAIL_SILENTLY": false,
    "TESTING": false,

    "MAIL_USERNAME": "GetMowed2@gmail.com",
    "MAIL_PASSWORD": "******",

    "MAIL_DEFAULT_SENDER": "GetMowed2@gmail.com"
}

requirements.txt:

bcrypt>=3.2.2
blinker>=1.5
cffi>=1.15.1
click>=8.1.3
cryptography>=37.0.4
dnspython>=2.2.1
email-validator>=1.2.1
Flask>=2.2.2
Flask-Login>=0.6.2
Flask-Mail>=0.9.1
Flask-SQLAlchemy>=2.5.1
Flask-User>=1.0.2.2
Flask-WTF>=1.0.1
greenlet>=1.1.2
gunicorn>=20.1.0
idna>=3.3
importlib-metadata>=4.12.0
itsdangerous>=2.1.2
Jinja2>=3.1.2
MarkupSafe>=2.1.1
passlib>=1.7.4
pkg_resources>=0.0.0
pycparser>=2.21
six>=1.16.0
SQLAlchemy>=1.4.40
Werkzeug>=2.2.2
WTForms>=3.0.1
zipp>=3.8.1

I found out that Flask-Mail is no longer supported and was not on pypi so I assume its not compatible with either updating the framework or updating python that I performed. The most recent update was about 8 years ago on the GitHub page.

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