Python/Python Programming
[Python] Gmail 보내기
Pydole
2018. 5. 18. 12:55
파이썬(Python)을 이용한 gmail 보내기
import smtplib
gmail_user = ''
gmail_password = ''
mailfrom = gmail_user
mailto = ''
subject = 'Gmail Test'
body = 'Python is Beautiful'
email_text = """
%s
%s
""" % (subject, body)
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(mailfrom, mailto, email_text)
server.close()
print('Gmail sent')
except:
print('Gmail Fail')