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 :: python how to drop columns from dataframe 
Python :: python factor number 
Python :: fast input python 
Python :: django email change sender name 
Python :: multi threading in python for 2 different functions with return 
Python :: how to convert response to beautifulsoup object 
Python :: transform image to rgb python 
Python :: iterate over a list python 
Python :: post list python 
Python :: convert number to char python 
Python :: confusion matrix with seaborn heatmap 
Python :: string list to int list python 
Python :: traversing dictionary in python 
Python :: python3.8 
Python :: select random img in python using os.listdir 
Python :: python binary 
Python :: To create a SparkSession 
Python :: pip change python version 
Python :: Appending rows to a DataFrame 
Python :: python condition question 
Python :: Flatten List in Python Using NumPy flat 
Python :: sorting decimal numbers in python 
Python :: tensorflow evaluation metrics 
Python :: for loop with index python 
Python :: reshape (n ) to (n 1) 
Python :: relative text size put text cv2 
Python :: Combine integer in list 
Python :: how to use ternary operater in python 
Python :: create tuples python 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =