Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- from email.message import EmailMessage
- from email.mime.text import MIMEText
- #for python 2.7
- def send_mail(from_email, to_email, subject, message, password):
- msg = MIMEText(message)
- msg['From'] = from_email
- msg['To'] = to_email
- msg['Subject'] = subject
- server = smtplib.SMTP("smtp.gmail.com", 587)
- server.starttls()
- server.login(from_email, password)
- server.sendmail(from_email, [to_email], msg.as_string())
- server.quit()
- #with subject
- def send_mail(from_email, to_email, subject, message, password):
- msg = EmailMessage()
- msg['From'] = from_email
- msg['To'] = to_email
- msg['Subject'] = subject
- msg.set_content(message)
- server = smtplib.SMTP("smtp.gmail.com", 587)
- server.starttls()
- server.login(from_email, password)
- server.send_message(msg)
- server.quit()
- #without subject
- def send_mail(from_email, to_email, body, password):
- server = smtplib.SMTP("smtp.gmail.com", 587)
- server.starttls()
- server.login(from_email, password)
- server.sendmail(from_email, to_email, body)
- server.quit()
Add Comment
Please, Sign In to add comment