Created
July 16, 2019 05:55
-
-
Save yskszk63/4323e26de5cd2328a97a3225d9a1e186 to your computer and use it in GitHub Desktop.
SendGrid Test by python smtplib
This file contains 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
#!/usr/bin/env python3 | |
import os | |
from smtplib import SMTP | |
from email.message import EmailMessage | |
def main(): | |
api_key = os.environ['api_key'] | |
# my addr -> spam, 'uso@dummy.ko' -> not spam | |
from_addr = os.environ['from_addr'] | |
to_addrs = os.environ['to_addrs'] | |
with SMTP(host='smtp.sendgrid.net', port=587) as smtp: | |
smtp.starttls() | |
smtp.login('apikey', api_key) | |
msg = EmailMessage() | |
msg.set_content("Hello, World!") | |
msg['Subject'] = 'Test Mail' | |
msg['From'] = from_addr | |
msg['To'] = to_addrs | |
smtp.set_debuglevel(1) | |
smtp.send_message(msg) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment