Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def callback_email(self, ch, method, properties, body):
- self.log_ ( " [x] Received %r" % (body,) )
- data = json.loads(body)
- grupo = data['grupo']
- template = data['template']
- words = data['words']
- lang = data['lang']
- to = data['to']
- name = data['name']
- # Prepare Mail
- fp = open('templates/%s.body.%s.html' % (template, lang), 'r')
- body = replace_all(fp.read(), words)
- fp.close()
- fp = open('templates/%s.subject.%s.txt' % (template, lang), 'r')
- # No anda
- #subject = fp.read()
- # Anda
- subject = "test massage"
- fp.close()
- myre = re.compile(r"cid:[a-zA-Z0-9_-]*")
- images = [ x.replace('cid:','') for x in myre.findall(body) ]
- # Prepare Mail
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = subject
- msgRoot['From'] = "GocloudOne Plataform <ibrick8@gmail.com>"
- msgRoot['To'] = "%s <%s>" % (name, to)
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- msgAlternative = MIMEMultipart('alternative')
- msgRoot.attach(msgAlternative)
- msgText = MIMEText('The HTML text cannot be shown')
- msgAlternative.attach(msgText)
- msgText = MIMEText(body, 'html')
- msgAlternative.attach(msgText)
- for image in images:
- fp = open("templates/%s.jpg" % image, 'rb')
- msgImage = MIMEImage(fp.read())
- fp.close()
- msgImage.add_header('Content-ID', "<%s>" % image)
- msgRoot.attach(msgImage)
- # Send Mail
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.ehlo()
- server.starttls()
- server.login("ibrick8@gmail.com", "xxxxxxx");
- server.sendmail("ibrick8@gmail.com", to, msgRoot.as_string());
- server.close()
Add Comment
Please, Sign In to add comment