Created
October 29, 2017 17:41
-
-
Save yskszk63/e7046678c9f17331cc47324803d1855f to your computer and use it in GitHub Desktop.
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
import os | |
import smtplib | |
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
dotenv = os.path.join(os.path.dirname(__file__), '.env') | |
with open(dotenv) as f: | |
exec(f.read(), None, os.environ) | |
from_addr = os.environ['FROM_ADDR'] | |
to_addr = os.environ['TO_ADDR'] | |
password = os.environ['PASSWORD'] | |
host = 'smtp-mail.outlook.com' | |
port = 587 | |
body = '''<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>test</title> | |
</head> | |
<body> | |
<h1>こんばんは</h1> | |
<p>こんばんは!メール</p> | |
<p>いかがおすごしでしょうか</p> | |
</body> | |
</html> | |
''' | |
msg = MIMEMultipart('HELLO') | |
msg.attach(MIMEText(body, 'html', 'UTF-8')) | |
msg['Subject'] = 'こんばんは!' | |
msg['From'] = from_addr | |
msg['To'] = to_addr | |
with smtplib.SMTP(host, port=port) as smtp: | |
smtp.starttls() | |
smtp.login(from_addr, password) | |
smtp.sendmail(from_addr, to_addr, msg.as_string()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment