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 :: python unit testing machine learning 
Python :: how to separate a string or int with comma in python 
Python :: python test if you can convert to int 
Python :: how to add value to to interger in python 
Python :: python get response headers 
Python :: python append element to array 
Python :: install hydra python 
Python :: count values pandas 
Python :: set image size mapltotlib pyplot 
Python :: discord.py how to use permissions 
Python :: How do you find the missing number in a given integer array of 1 to 100? 
Python :: django making a custom 403 page 
Python :: remove all rows without a value pandas 
Python :: while loop user input python 
Python :: How to Create Caesar Cipher Using Python 
Python :: python assers 
Python :: star pattern in python 
Python :: how to append data to csv file in python without replacing the already present text 
Python :: from imblearn.over_sampling import smote error 
Python :: how to send emails in python 
Python :: pygame how to get surface lenght 
Python :: memory used by python program 
Python :: flask server not reloading 
Python :: how to use print function in python 
Python :: save dictionary to file numpy 
Python :: Efficiently count zero elements in numpy array? 
Python :: lista to txt python 
Python :: selenium python class contains 
Python :: python import worldcloud 
Python :: how to read tuples inside lists python 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =