123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import smtplib
- import traceback
- import os
- from email.mime.text import MIMEText
- from email.mime.image import MIMEImage
- from email.mime.multipart import MIMEMultipart
- from email.message import EmailMessage
- import codecs
- import jinja2
- #gmail_user = 'edm@choozmo.com'
- #gmail_user = 'video@choozmo.com'
- #gmail_password='Chuz2020'
- gmail_user = 'jared@choozmo.com'
- gmail_password='jgferbhelzrtgsbb'
- #gmail_password='wqdsyqwvppmubitv'
- sent_from = gmail_user
- #toaddr='jeweiliang@gmail.com'
- toaddr='jeweiliang@gmail.com'
- #to = ['jared@choozmo.com','nina.huang@choozmo.com','ana@choozmo.com','ming@choozmo.com','mike@choozmo.com','andy@choozmo.com','hana@choozmo.com','stacy@choozmo.com','wen@choozmo.com','yukyo@choozmo.com','fxp87257@gmail.com','noodlesloves@gmail.com']
- to = [toaddr]
- #to = ['jared@choozmo.com']
- msg = MIMEMultipart()
- msg['Subject'] = '合作洽談 | ChoozMo '
- msg['From'] = 'jared@choozmo.com'
- msg['To'] = toaddr
- image_paths=['c:/tmp/images/image-1.png','c:/tmp/images/image-2.png','c:/tmp/images/image-3.png','c:/tmp/images/image-4.png','c:/tmp/images/image-5.png','c:/tmp/images/image-6.png','c:/tmp/images/image-7.jpeg','c:/tmp/images/image-8.jpeg']
- msgAlternative = MIMEMultipart('alternative')
- msg.attach(msgAlternative)
- #fr=codecs.open('c:/tmp/final.html','r','utf-8')
- fr=codecs.open('c:/tmp/index.html','r','utf-8')
- content=fr.read()
- fr.close()
- display={}
- display['custname']='敬啟者'
- display['client']='j22332'
- display['email']=toaddr
- display['campaign']='20220305-test'
- templateLoader = jinja2.FileSystemLoader(searchpath='c:/tmp')
- templateEnv = jinja2.Environment(loader=templateLoader)
- TEMPLATE_FILE = 'index.html'
- template = templateEnv.get_template(TEMPLATE_FILE)
- outputText = template.render(display=display)
- content=outputText
- text = MIMEText(content,'html','utf-8')
- counter = 1
- for fp in image_paths:
- fp = open(fp, 'rb')
- msgImage = MIMEImage(fp.read())
- fp.close()
- # Define the image's ID as referenced above
- msgImage.add_header('Content-ID', '<image'+str(counter)+'>')
- msgAlternative.attach(msgImage)
- counter += 1
- msgAlternative.attach(text)
- try:
- server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
- server.ehlo()
- server.login(gmail_user, gmail_password)
- server.sendmail(sent_from, to, msg.as_string())
- server.close()
- print ('Email sent!')
- except:
- traceback.print_exc()
- print ('Something went wrong...')
|