0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

メール文章のみ送りたい

Posted at

お決まり文章

qiita.rb
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

注目ポイントは、def関数の中身

メール設定
def send_email_with_pdfs(sender_email, recipient_email, subject, body, app_password):
   msg = MIMEMultipart()  # ← msg を MIMEMultipart() で作成
   msg['From'] = sender_email
   msg['To'] = recipient_email
   msg['Subject'] = subject

   msg.attach(MIMEText(body, 'plain'))

   try:
       with smtplib.SMTP('smtp.gmail.com', 587) as server:
           server.starttls()  # セキュア接続を開始
           server.login(sender_email, app_password)  
           
           server.sendmail(sender_email, recipient_email, msg.as_string())
           print('成功!')
   except Exception as e:
       print(f"メール送れんかったよ: {e}")

大事ポイント:def関数の中に、一番最初にいるもん

qiita.rb
   msg = MIMEMultipart() 
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?