Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to add a file to an email in python

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders


SUBJECT = "Email Data"

msg = MIMEMultipart()
msg['Subject'] = SUBJECT 
msg['From'] = self.EMAIL_FROM
msg['To'] = ', '.join(self.EMAIL_TO)

part = MIMEBase('application', "octet-stream")
part.set_payload(open("text.txt", "rb").read())
Encoders.encode_base64(part)

part.add_header('Content-Disposition', 'attachment; filename="text.txt"')

msg.attach(part)

server = smtplib.SMTP(self.EMAIL_SERVER)
server.sendmail(self.EMAIL_FROM, self.EMAIL_TO, msg.as_string())
Comment

PREVIOUS NEXT
Code Example
Python :: python define class 
Python :: pandas resample groupby 
Python :: get body from request python 
Python :: find frequency of numbers in list python 
Python :: django group with permission 
Python :: generate binary number in python 
Python :: python string to lower 
Python :: python advanced programs time module 
Python :: python bubble sort 
Python :: unique value python 
Python :: how to clear dictionary in python 
Python :: max heap python 
Python :: itertools .cycle() 
Python :: correlation for specific columns 
Python :: django get latest object 
Python :: django queryset count 
Python :: pandas dataframe get first n rows 
Python :: import stock data from yahoo finance 
Python :: python @property 
Python :: python max function recursive 
Python :: how to select li element in selenium python 
Python :: scikit learn roc curve 
Python :: merge two query sets django 
Python :: print input in python 
Python :: if condition dataframe python 
Python :: numpy dot product 
Python :: plotly color specific color 
Python :: pathlib path forward or back slahses 
Python :: how to declare np datetime 
Python :: python dictionary sort by value then alphabetically 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =