def send_raw_email(self, sender, subject, body, recipient_list, attachment_path): msg = MIMEMultipart() msg['Subject'] = subject msg['From'] = sender to_list = "" for idx, data in enumerate(recipient_list): if idx < len(recipient_list) - 1: to_list += data + "," else: to_list += data msg['To'] = to_list msg.premable = 'Multipart Message.\n' # Assembling Mail body part = MIMEText(body) msg.attach(part) # Assembling Attachment part = MIMEApplication(open(attachment_path, 'rb').read()) part.add_header('Content-Disposition', 'attachment', filename=os.path.basename(attachment_path)) msg.attach(part) # Send RAW email if self.ses_conn != None: self.ses_conn.send_raw_email(msg.as_string(), source=msg['From'], destinations=recipient_list) else: print "Connection object is null!!"
def send_email(casino, mail, recepient_email, recepient_name, attach=""): if casino == 1: smtp_server = "mail.casinoextreme.eu" sender_email = "*****@*****.**" support_email = "*****@*****.**" password = "******" subject = f"{recepient_name.title()}, your Loyalty Reward is ready!" signed = "Anna" cas_text = "Casino Extreme" cas_link = "www.casinoextreme.eu" phone = "1-800-532-4561" filename = "extreme.csv" # for attachement part elif casino == 2: smtp_server = "mail.casinobrango.com" sender_email = "*****@*****.**" support_email = "*****@*****.**" password = "******" subject = f"{recepient_name.title()}, your Loyalty Reward is ready!" signed = "Anna" cas_text = "Casino Brango" cas_link = "www.casinobrango.com" phone = "1-800-532-4561" filename = "brango.csv" # for attachement part elif casino == 3: smtp_server = "mail.yabbycasino.com" sender_email = "*****@*****.**" support_email = "*****@*****.**" password = "******" subject = f"{recepient_name.title()}, you got a Loyalty Reward! Congrats!" signed = "Ethan" cas_text = "Yabby Casino" cas_link = "www.yabbycasino.com" phone = "1-800-876-3456" filename = "yabby.csv" # for attachement part if mail == 1: ### REWARD MESSAGE CONTENT text = """\ Dear %s, Hope you are well. Thank you for your patronage. A loyalty reward has been added to your account, but you can only use it today! We hope it brings you luck! Please let us know if you need any assistance. Sincerely, %s %s 24/7 Live Support Chat: %s E-mail: %s Phone: %s""" % (recepient_name, signed, cas_text, cas_link, support_email, phone,) html="""\ <html> <body> <p> Dear %s, <br><br>Hope you are well. <br><br>Thank you for your patronage. <b>A loyalty reward has been added to your account</b>, but you can only use it today! We hope it brings you luck! <br><br>Please let us know if you need any assistance. <br><br>Sincerely, <br>%s <br><b>%s</b> <br><br><i>24/7 Live Support <br>Chat: %s <br>E-mail: %s <br>Phone: %s</i> </p> </body> </html> """ % (recepient_name, signed, cas_text, cas_link, support_email, phone,) elif mail == 2: ### PENDING MESSAGE CONTENT text = """\ Dear %s, Hope you are well. Thank you for your patronage. A loyalty reward has been prepared for your account, but you can only use it today! We didn't add it just yet so as not to disturb your current play. Once you are done, be sure contact our friendly Customer Service team, and they will have it added to your account. We hope it will prove lucky! Please let us know if you need any assistance. Sincerely, %s %s 24/7 Live Support Chat: %s E-mail: %s Phone: %s""" % (recepient_name, signed, cas_text, cas_link, support_email, phone,) html="""\ <html> <body> <p> Dear %s, <br><br>Hope you are well. <br><br>Thank you for your patronage. <b>A loyalty reward has been prepared for your account</b>, but you can only use it today! We didn't add it just yet so as not to disturb your current play. <br><br>Once you are done, be sure contact our friendly Customer Service team, and they will have it added to your account. We hope it will prove lucky! <br><br>Please let us know if you need any assistance. <br><br>Sincerely, <br>%s <br><b>%s</b> <br><br><i>24/7 Live Support <br>Chat: %s <br>E-mail: %s <br>Phone: %s</i> </p> </body> </html> """ % (recepient_name, signed, cas_text, cas_link, support_email, phone,) elif mail == 3: ### RERPORT MESSAGE CONTENT subject = f"Notice: {cas_text} Daily Rewards Report" recepient_email = "*****@*****.**" text = """\ Hello! Please find the report of today's Daily Rewards in the attached CSV file. Kind Regards, Stefan """ if attach == "": # customer emails message = MIMEMultipart("alternative") message["Subject"] = subject message["From"] = f"{cas_text} <{sender_email}>" message["To"] = recepient_email part1 = MIMEText(text, "plain") part2 = MIMEText(html, "html") message.attach(part1) message.attach(part2) else: # attachment mail message = MIMEMultipart() message["From"] = f"{cas_text} <{sender_email}>" message["To"] = recepient_email message["Subject"] = subject message.premable = subject part1 = MIMEText(text, "plain") message.attach(part1) ctype, encoding = mimetypes.guess_type(attach) if ctype is None or encoding is not None: ctype = "application/octet-stream" maintype, subtype = ctype.split("/", 1) if maintype == "text": fp = open(attach) attachment = MIMEText(fp.read(), _subtype=subtype) fp.close() else: fp = open(attach, "rb") attachment = MIMEBase(maintype, subtype) attachment.set_payload(fp.read()) fp.close() encoders.encode_base64(attachment) attachment.add_header("Content-Disposition", "attachment", filename=filename) message.attach(attachment) port = 465 context = ssl.create_default_context() with smtplib.SMTP_SSL(host=smtp_server,port=port,context=context) as s: s.login(sender_email, password) s.sendmail(from_addr=sender_email, to_addrs=recepient_email, msg=message.as_string())