The same way, using msg.attach
:
from email.mime.text import MIMEText
filename = "text.txt"
f = file(filename)
attachment = MIMEText(f.read())
attachment.add_header('Content-Disposition', 'attachment', filename=filename)
msg.attach(attachment)
Related Contents:
- How to send an email with Gmail as provider using Python?
- How to send email to multiple recipients using python smtplib?
- How to send email via Django?
- Sending mail error with python smtplib
- How to send email attachments?
- Send HTML emails with Python
- Sending Multipart html emails which contain embedded images
- How to send an email with Python?
- The smtplib.server.sendmail function in python raises UnicodeEncodeError: ‘ascii’ codec can’t encode character
- python: how to send mail with TO, CC and BCC?
- Django sending email
- Receive and send emails in python
- Sending mail from Python using SMTP
- Python : How to parse the Body from a raw email , given that raw email does not have a “Body” tag or anything
- smtplib sends blank message if the message contain certain characters
- Login credentials not working with Gmail SMTP
- What are the “parts” in a multipart email?
- Python email quoted-printable encoding problem
- Specify a sender when sending mail with Python (smtplib)
- Checking email with Python
- How can I get an email message’s text content using Python?
- gmail login failure using python and imaplib
- Python smtplib proxy support
- How to send an email using python after Google’s policy update on not allowing just username and password?
- Embed picture in email
- Parsing email with Python
- How do I profile a Python script?
- How to fix “Attempted relative import in non-package” even with __init__.py
- Animated sprite from few images
- Cannot find module cv2 when using OpenCV
- Python subprocess/Popen with a modified environment
- How to adjust padding with cutoff or overlapping labels
- How do I .decode(‘string-escape’) in Python 3?
- Auto reloading python Flask app upon code changes
- how to convert an RGB image to numpy array?
- Integer overflow in numpy arrays
- Python sorting by multiple criteria
- How to prevent Google Colab from disconnecting?
- Insert an item into sorted list in Python
- Extract upper or lower triangular part of a numpy matrix
- Cannot import QtWebKitWidgets in PyQt5
- Fast arbitrary distribution random sampling (inverse transform sampling)
- How can Geckodriver/Firefox work without Marionette? (running python selenium 3 against FF 53)
- How to monkey patch Django?
- deleting rows in numpy array
- Converting a PDF to a series of images with Python
- Why use setattr() and getattr() built-ins?
- print memory address of Python variable [duplicate]
- Remove NaN/NULL columns in a Pandas dataframe?
- Python3: writing csv files