Add CC recipient to a email?

19584
1
Jump to solution
08-13-2018 09:25 AM
by Anonymous User
Not applicable

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."
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor
1 Reply
XanderBakker
Esri Esteemed Contributor

There is an example you can check here: email - python: how to send mail with TO, CC and BCC? - Stack Overflow