Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

GmailでPythonを使って送信する

結論

import smtplib
from email.utils import formatdate
from os.path import basename
from email.mime.text import MIMEText
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart


EMAIL_SENDER_ADDRESS = ''
EMAIL_SENDER_PASSWORD = ''

def sendEmail(message, subject):
    #送り主
    from_email = EMAIL_SENDER_ADDRESS
    from_password = EMAIL_SENDER_PASSWORD

    # 送り先
    to_email = [Env.EMAIL_RECIEVE_ADDRESS]

    # メールの内容
    msg = MIMEMultipart()
    body = MIMEText(message, "html")
    msg.attach(body)
    msg["Subject"] = subject
    msg["To"] = ",".join(to_email)
    msg["From"] = from_email

    gmail = smtplib.SMTP("smtp.gmail.com", 587)
    gmail.starttls()
    gmail.login(from_email, from_password)
    gmail.send_message(msg)
osakasho
PythonでDeepLearningしたい人生。 ちょっとまともなGPUのPCを購入してゴリゴリ機械学習させてゆく。
https://shomyapp.net/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away