Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. def send_mail(send_from, send_to, subject, text, files=None, server="mail.directservices.bg"):
  2.     assert isinstance(send_to, list)
  3.  
  4.     username = ''
  5.     password = ''
  6.  
  7.     msg = MIMEMultipart()
  8.     msg['From'] = send_from
  9.     msg['To'] = COMMASPACE.join(send_to)
  10.     msg['Date'] = formatdate(localtime=True)
  11.     msg['Subject'] = subject
  12.  
  13.     msg.attach(MIMEText(text.encode('utf-8'), 'html', 'utf-8'))
  14.  
  15.     for f in files or []:
  16.         with open(f, "rb") as fil:
  17.             part = MIMEApplication(
  18.                 fil.read(),
  19.                 Name=basename(f)
  20.             )
  21.         # After the file is closed
  22.         part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
  23.         msg.attach(part)
  24.  
  25.     smtp = smtplib.SMTP(server)
  26.     smtp.ehlo()
  27.     smtp.starttls()
  28.     smtp.login(username, password)
  29.     smtp.sendmail(send_from, send_to, msg.as_string())
  30.     smtp.close()
  31.  
  32. send_mail("danielbsu9@gmail.com", ["danielbsu@abv.bg"], "subj", "hello from test pizza site!", files=None, server="smtp.gmail.com:587")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement