I'm wanting to add CC recipients to the email code below. Anyone have an idea on how I can alter this code?
# Import smtplib for the actual sending function
import smtplib
# For guessing MIME type
import mimetypes
# Import the email modules we'll need
import email
import email.mime.application
SERVER = "dhsrhshseh@test.com"
# Create a text/plain message
msg = email.mime.Multipart.MIMEMultipart()
msg['Subject'] = 'Test Subject'
msg['From'] = "MyEmail@test.com"
msg['To'] = "ToEmail@test.com"
# The main body is just another attachment
body = email.mime.Text.MIMEText("""This is a test""")
msg.attach(body)
# PDF attachment
filename="Test.pdf"
fp=open(filename,'rb')
att = email.mime.application.MIMEApplication(fp.read(),_subtype="pdf")
fp.close()
att.add_header('Content-Disposition','attachment',filename=filename)
msg.attach(att)
server = smtplib.SMTP(SERVER)
server.sendmail('MyEmail@test.com', msg['To'], msg.as_string())
server.quit()
print "Email sent."
Solved! Go to Solution.
There is an example you can check here: email - python: how to send mail with TO, CC and BCC? - Stack Overflow
There is an example you can check here: email - python: how to send mail with TO, CC and BCC? - Stack Overflow