Send Japanese email with Python3

Send Japanese emails with Python3.

#!/bin/env python3

import smtplib
from email.mime.text import MIMEText
import datetime

jp='iso-2022-jp'

# file.The content you want to send is included in txt
fp = open('file.txt')
raw_msg = fp.read()
msg = MIMEText(raw_msg.encode(jp), 'plain', jp,)
fp.close()

fromaddr = "[email protected]"
toaddr = "[email protected]"

#Used when specifying Subject
d = datetime.datetime.today()
date = d.strftime("%Y-%m-%d")

msg['Subject'] = date+"Usage information"
msg['From'] = fromaddr
msg['To'] = toaddr


try:
    server = smtplib.SMTP('localhost')
    server.send_message(msg)
    print("Successfully sent email")
except Exception:
    print("Error: unable to send email")

##reference
## http://w.builwing.info/2013/09/21/python3-3%E3%81%A7%E3%83%A1%E3%83%BC%E3%83%AB%E9%80%81%E4%BF%A1/

Recommended Posts

Send Japanese email with Python3
Send email with Python
[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.
HTML email with image to send with python
Send email with Django
Validate E-Mail 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 email in Python (Outlook)
Japanese morphological analysis with Python
Send using Python with Gmail
Easy email sending with haste python3
Speak Japanese text with OpenJTalk + python
Note: Send an email with Django
Send multipart / form-data with python requests
Send image with python, save with php
[Python] Send an email from gmail with two-step verification set
I tried various methods to send Japanese mail with Python
Python 3.6 email library
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Generate Japanese test data with Python faker
Send email to multiple recipients in Python (Python 3)
Twilio with Python
Integrate with Python
Download Japanese stock price data with python
I tried sending an email with python.
Notes on doing Japanese OCR with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
How to display python Japanese with lolipop
[Python] Let's make matplotlib compatible with Japanese
with syntax (Python)
Japanese with matplotlib
Bingo with python
Zundokokiyoshi with python
How to enter Japanese with Python curses
Excel with Python
Microcomputer with Python
Cast with python
What to do if you couldn't send an email to Yahoo with Python.
Send an email to a specific email address with python without SMTP settings
Send email with SES in Python and short message with SMS on SNS
Send a message to LINE with Python (LINE Notify)
Try it with Word Cloud Japanese Python JupyterLab.
Handle zip files with Japanese filenames in Python 3
Sample to send slack notification with python lambda
Create an image with characters in python (Japanese)
Extract zip with Python (Japanese file name support)
Extract email attachments received in Thunderbird with Python
I tried sending an email with SendGrid + Python
Send HTTP with Basic authentication header in Python