-
-
Save cuijiudai/6475495 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def try_sending_email(): | |
import os, smtplib, mimetypes | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEBase import MIMEBase | |
from email.MIMEText import MIMEText | |
from email.Encoders import encode_base64 | |
gmail_user = '[user]@gmail.com' | |
gmail_password = '[password]' | |
recipient = '[recipient]' | |
msg = MIMEMultipart() | |
msg['From'] = gmail_user | |
msg['To'] = recipient | |
msg['Subject'] = 'Hello!' | |
msg.attach(MIMEText('Hello')) | |
mail_server = smtplib.SMTP('smtp.gmail.com', 587) | |
mail_server.set_debuglevel(1) | |
mail_server.ehlo() | |
mail_server.starttls() | |
mail_server.ehlo() | |
mail_server.login(gmail_user, gmail_password) | |
mail_server.sendmail(gmail_user, recipient, msg.as_string()) | |
mail_server.close() | |
print('Sent email to %s' % recipient) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment