Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. from email import encoders
  2. from email.mime.multipart import MIMEMultipart
  3. from email.mime.application import MIMEApplication
  4. from email.mime.text import MIMEText
  5. from smtplib import SMTP
  6.  
  7.  
  8. def send_mail(to,subject,body,attachments=False):
  9.     msg = MIMEMultipart()
  10.  
  11.     msg['From'] = 'carusoapi@carusojrea.com.br'
  12.     msg['To'] = to
  13.     msg['Subject'] = subject
  14.  
  15.     msg.attach(MIMEText(body, 'html'))
  16.  
  17.     if attachments != False:
  18.         for file in attachments:
  19.             part = MIMEApplication(file[0].getvalue())
  20.             part.add_header('Content-Disposition','attachment', filename=file[1])
  21.             msg.attach(part)
  22.  
  23.     with SMTP('smtp-mail.outlook.com',587) as outlook:
  24.         outlook.starttls()
  25.         outlook.login('gabriel@carusojrea.com.br', ';)')
  26.         outlook.sendmail('carusoapi@carusojrea.com.br',to, msg.as_string().encode('utf-8'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement