Skip to content

Instantly share code, notes, and snippets.

@samsee
Last active March 15, 2020 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsee/9745c1bec8c125a742d733e96bd46caa to your computer and use it in GitHub Desktop.
Save samsee/9745c1bec8c125a742d733e96bd46caa to your computer and use it in GitHub Desktop.
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