I
I
Iqbol2015-05-14 09:04:02
MongoDB
Iqbol, 2015-05-14 09:04:02

How to send data from a Flask/MongoDB web application to an email address?

Greetings !

There is a small blog that mainly adds posts, so here's how you can organize it so that you can send user posts to specific email addresses. The blog is written in Flask/MongoDB, I'm still green in this business, I'm asking for help from experienced developers.

Thanks in advance !

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2015-05-14
@deliro

habrahabr.ru/post/234737 I
also advise the rest of the articles from this series.

R
Roman, 2015-05-15
@skipirich

pip install FlaskMail

from flask_mail import Mail
from flask.ext.mail import 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)


def send_post(email, post):
    send_email('This is a new post',
    '[email protected]',
    [email],
    post,
    '<p>' + post + '</p>')

the third parameter is a list, i.e. you can throw a list with several addresses.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question