Advertisement
Guest User

send_email.py

a guest
Dec 31st, 2018
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. from flask import Flask
  2. from flask_mail import Mail, Message
  3. import os
  4.  
  5. app = Flask(__name__)
  6.  
  7. app.config.update(
  8.     MAIL_SERVER = 'smtp@gmail.com',
  9.     MAIL_PORT = 465,
  10.     MAIL_USE_SSL = True,
  11.     MAIL_USERNAME = 'emailku@gmail.com',
  12.     MAIL_PASSWORD = 'emailkupass123'
  13. )
  14.  
  15. mail = Mail(app)
  16.  
  17. @app.route('/')
  18. def index():
  19.     msg = Message(subject="Hello",
  20.                       sender='emailpengirim@gmail.com',
  21.                       recipients=["alsaskarmirando@gmail.com"], # replace with your email for testing
  22.                       body="This is a test email I sent with Gmail and Python!")
  23.     mail.send(msg)
  24.  
  25.     return 'Email berhasil dikirim'
  26.  
  27. if __name__ == '__main__':
  28.     app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement