LoginSignup
7
7

More than 5 years have passed since last update.

Pythonによるメール送信

Last updated at Posted at 2014-10-18

基本

# coding: UTF-8

import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email import charset
from email.Utils import formatdate

# Header 付加
def create_message(from_addr,to_addr,subject,body):
    message = MIMEText(body)
    message['Subject'] = subject
    message['From'] = from_addr
    message['To'] = to_addr
    message['Date'] = formatdate()
    return message

# メール送信
def send(from_addr,to_addr, msg):
    s = smtplib.SMTP('localhost:25')    s.sendmail(from_addr, [to_addr], msg.as_string())
    s.close()
7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7