Send email with Python

Basic

# 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 addition
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

#send e-mail
def send(from_addr,to_addr, msg):
    s = smtplib.SMTP('localhost:25')    s.sendmail(from_addr, [to_addr], msg.as_string())
    s.close()

Recommended Posts

Send email with Python
Send Japanese email with Python3
[Python] Send email
[Python] Send email
[Automation] Send Outlook email with Python
[Python] Send an email with outlook
Send email via gmail with Python 3.4.3.
Send email with Django
Validate E-Mail with Python
HTML email with image to send with python
Send an email with Amazon SES + Python
Send an email to Spushi's address with python
Send an email with Excel attached in Python
Send using Python with Gmail
Note: Send an email with Django
Send multipart / form-data with python requests
Send image with python, save with php
Python 3.6 email library
FizzBuzz with Python3
Scraping with Python
Statistics with python
[Python] Send an email from gmail with two-step verification set
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Send email to multiple recipients in Python (Python 3)
I tried sending an email with python.
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Socket communication with Python
Data analysis with python 2
Try scraping with Python.
Send a message to LINE with Python (LINE Notify)
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Run prepDE.py with python3
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
Kernel Method with Python
What to do if you couldn't send an email to Yahoo with Python.