SMTPでメールを送信する

Python PythonにはSMTP用のライブラリが標準で用意されている。 #! /usr/bin/env python import smtplib server = smtplib.SMTP(host="localhost", port=1025) server.set_debuglevel(1) server.sendmail("[email protected]", ["[email protected]"], "OK") server.quit()...

 · 1 min · しむどん三度無視

PythonでGmailのSMTPサーバーを使ってEmailを送信する

import os import smtplib from email.mime.text import MIMEText from email.utils import formatdate from_addr = os.environ["EMAIL_HOST_USER"] to_addr = os.environ["EMAIL_TARGET_EMAIL"] smtpobj = smtplib.SMTP(os.environ["EMAIL_HOST"], int(os.environ["EMAIL_PORT"])) smtpobj.ehlo() smtpobj.starttls() smtpobj.ehlo() smtpobj.login(os.environ["EMAIL_HOST_USER"], os.environ["EMAIL_HOST_PASSWORD"]) msg = MIMEText('body Message') msg['Subject'] = 'subject' msg['From'] = from_addr msg['To'] = to_addr msg['Date'] = formatdate() smtpobj.sendmail(from_addr, to_addr, msg.as_string()) smtpobj.close()...

 · 1 min · しむどん三度無視