Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import smtplib
# 이메일 보내기 : restock
class EmailNotification:
def __init__(self, gmail_user, gmail_password):
self.gmail_user = gmail_user
self.gmail_password = gmail_password
def sendMessage(self, sent_from, to, subject, body):
email_text = """\
From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(to), subject, body)
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(self.gmail_user, self.gmail_password)
server.sendmail(sent_from, to, email_text)
server.close()
print('Email sent..')
except:
print('Something went wrong...')
if __name__ == "__main__":
gmail_user = 'your-email@gmail.com'
gmail_pass = 'your-password'
email = EmailNotification(gmail_user, gmail_pass)
email.sendMessage(gmail_user, [gmail_user], 'Hello', 'World')
import smtplib
# 이메일 보내기 샘플 코드
# from : https://stackabuse.com/how-to-send-emails-with-gmail-using-python/
gmail_user = 'your-email@gmail.com'
gmail_password = 'your-password'
sent_from = gmail_user
to = [gmail_user]
subject = 'OMG Super Important Message'
body = "Hey, what's up?\n\n- You"
email_text = """\
From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(to), subject, body)
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(sent_from, to, email_text)
server.close()
print('Email sent!')
except:
print('Something went wrong...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment