Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

send email with flask

# In your command line run: 
# pip install Flask-Mail

# Then you can start sending emails easily! Enjoy! :)
from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)

app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'yourId@gmail.com'
app.config['MAIL_PASSWORD'] = '*****'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True // True if Port = 465
mail = Mail(app)

@app.route("/")
def index():
   msg = Message('Hello', sender = 'yourId@gmail.com', recipients = ['someone1@gmail.com'])
   msg.body = "Hello Flask message sent from Flask-Mail"
   
   # You can also use msg.html to send html templates!
   # Example:
   # msg.html = render_template("hello.html") # Template should be in 'templates' folder
   
   mail.send(msg)
   return "Your email has been sent!"

if __name__ == '__main__':
   app.run(debug = True)
Comment

flask send email gmail

if __name__ == '__main__':
    with app.app_context():
        msg = Message(subject="Hello",
                      sender=app.config.get("MAIL_USERNAME"),
                      recipients=["<recipient email here>"], # replace with your email for testing
                      body="This is a test email I sent with Gmail and Python!")
        mail.send(msg)
Comment

sending email with flask_mail

from flask import Flask
from flask_mail import Mail

app = Flask(__name__)
mail = Mail(app)
Comment

PREVIOUS NEXT
Code Example
Python :: numpy copy a array vertical 
:: python how to drop columns from dataframe 
::  
Python ::  
Python :: sphinx autodoc command 
Python :: python loc 
Python :: change markersize in legend matplotlib 
:: how to count substring in a string in python 
Python :: make gif from images in python 
Python :: python how to extract a string from another string 
:: python slice list 
::  
Python :: rename colums dataframe pandas 
Python :: google assistant in windows 10 
Python :: how to improve accuracy of random forest classifier 
Python :: while loop in python 
Python :: python compare each item of one list 
:: python namedtuples 
Python :: Python Split list into chunks using for loop 
Python :: python str of list 
Python :: python string encode 
Python :: find index of element in array python 
Python :: quantile-quantile plot python 
Python :: python return to top of loop 
Python :: check null all column pyspark 
Python :: python keyboard input 
Python :: Sum of Product 1 
::  
Python :: run python version from terminal 
Python :: groupby get last group 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =