Created
November 7, 2018 13:36
-
-
Save smd877/cd365380d789ce40c1f2e83ccec710ba to your computer and use it in GitHub Desktop.
AWS LambdaでGmailの送信
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
#coding: UTF-8 | |
import os | |
import smtplib | |
from email.mime.text import MIMEText | |
# Gmailアカウント | |
FROM_ADDR = os.environ['mail_from_addr'] | |
# アプリパスワード | |
PASSWD = os.environ['mail_passwd'] | |
# 送信先メールアドレス | |
TO_ADDR = os.environ['mail_to_addr'] | |
def lambda_handler(event, context): | |
# メールタイトル | |
title_text = 'Mail Title' | |
# メール本文 | |
body_text = 'Mail Body Message.' | |
msg = MIMEText(body_text) | |
msg['Subject'] = title_text | |
msg['From'] = FROM_ADDR | |
msg['To'] = TO_ADDR | |
s = smtplib.SMTP('smtp.gmail.com', 587) | |
s.ehlo() | |
s.starttls() | |
s.login(FROM_ADDR, PASSWD) | |
s.sendmail(FROM_ADDR, 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