How do you send an email with an attachment in Python?

How do you send an email with an attachment in Python?
Answer
In a string, write the body of the message you want to send, namely body. Now, attach the body with the instance msg using
attach function.
…
For adding an attachment, you need to import:
  1. import smtplib.
  2. mime. multipart import MIMEMultipart.
  3. mime. text import MIMEText.
  4. mime. base import MIMEBase.
  5. from email import encoders.
 

Tìm kiếm

Back
Top