Created
March 27, 2020 14:47
-
-
Save smd877/46261bb759f327a8160ca2d66eefa8aa to your computer and use it in GitHub Desktop.
AWS LambdaでSESを使ってメールを送信
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
import os | |
import smtplib | |
from email.mime.text import MIMEText | |
def lambda_handler(event, context): | |
to_addr = event.get('to_addr') | |
subject = event.get('subject') | |
body = event.get('body') | |
msg = MIMEText(body) | |
msg['Subject'] = subject | |
msg['From'] = os.environ['MAIL_ADDR_FROM'] | |
msg['To'] = to_addr | |
s = smtplib.SMTP(os.environ['MAIL_SMTP_ENDPOINT'], os.environ['MAIL_SMTP_PORT']) | |
s.ehlo() | |
s.starttls() | |
s.login(os.environ['MAIL_LOGIN_ID'], os.environ['MAIL_LOGIN_PASS']) | |
s.sendmail(os.environ['MAIL_ADDR_FROM'], to_addr, msg.as_string()) | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment