1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pythonでメールを飛ばすモジュールを作った話

Posted at

##作ったものの概要
smtplibとかMIMETextを使ってメールを飛ばすモジュール作ってみました。
引数に件名、本文、送信元、送信先、Ccを指定することで送信が可能です。
今回利用していた送信元メールが認証不要のものだったので、認証機能はとくに作ってません。
多分server.loginとかやればできると思います。(試してませんが。。。)
##コード

mail.py

import smtplib
from email.mime.text import MIMEText

def send_mail(subject, body, f_email, t_email, c_email):
    # 送受信先とメール件名、本文の指定
    msg = MIMEText(body, "html")
    msg["Subject"] = subject
    msg["To"] = t_email
    msg["From"] = f_email
    msg["Cc"] = c_email  
    # サーバを指定する。サーバーとポートにメールサーバー名とポート番号を渡しておく
    server = smtplib.SMTP(サーバー, ポート) 
    # メールを送信する
    server.send_message(msg)
    # 閉じる
    server.quit()

    return
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?