Answer the question
In order to leave comments, you need to log in
How to make flask-mail and postfix friends?
Friends, I have ubuntu 16.04 on my machine with mail on board. From the console tried to send letters - everything works. I attached flask-mail to the application and send an email, but nothing comes out.
flask-mail configuration
msg = Message("Hello", sender="****@pc", recipients=["*****@yandex.ru"])
msg.body = "testing"
msg.html = "<b>testing</b>"
mail.send(msg)
Answer the question
In order to leave comments, you need to log in
Does this configuration really work for me in conjunction with flask-mail and postfix?
import os
# FLASK-MAIL SETTINGS
MAIL_USERNAME = os.getenv('MAIL_USERNAME', '[email protected]_your_host.com')
MAIL_PASSWORD = os.getenv('MAIL_PASSWORD', '')
MAIL_DEFAULT_SENDER = os.getenv('MAIL_DEFAULT_SENDER', '[email protected]_your_host.com')
MAIL_SERVER = os.getenv('MAIL_SERVER', 'localhost')
MAIL_PORT = int(os.getenv('MAIL_PORT', '25'))
MAIL_USE_SSL = int(os.getenv('MAIL_USE_SSL', False))
from flask_mail import Mail, Message
mail = Mail(app)
def send_email(subject, sender, recipients, text_body, html_body):
msg = Message(subject, sender=sender, recipients=recipients)
msg.body = text_body
msg.html = html_body
mail.send(msg)
from flask import Flask
from flask_mail import Mail, Message
import os
app = Flask(__name__)
# FLASK-MAIL SETTINGS
app.config['SECRET_KEY'] = 'dsfdsfdsfdsfdsf'
app.config['MAIL_USERNAME'] = os.getenv('MAIL_USERNAME', '[email protected]')
app.config['MAIL_PASSWORD'] = os.getenv('MAIL_PASSWORD', '')
app.config['MAIL_DEFAULT_SENDER'] = os.getenv(
'MAIL_DEFAULT_SENDER', '[email protected]')
app.config['MAIL_SERVER'] = os.getenv('MAIL_SERVER', 'localhost')
app.config['MAIL_PORT'] = int(os.getenv('MAIL_PORT', '25'))
app.config['MAIL_USE_SSL'] = int(os.getenv('MAIL_USE_SSL', False))
mail = Mail(app)
def send_email(subject, sender, recipients, text_body, html_body):
msg = Message(subject, sender=sender, recipients=recipients)
msg.body = text_body
msg.html = html_body
mail.send(msg)
@app.route('/')
def home_page():
send_email('subj', '[email protected]', ['[email protected]'], 'Hello txt',
'<h1>Hello html</h1>')
return "100500"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question