AnsweredAssumed Answered

Add CC recipient to a email?

Question asked by vonmoosa on Aug 13, 2018
Latest reply on Aug 13, 2018 by xander_bakker

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."

Outcomes