Guest User

Untitled

a guest
Dec 11th, 2018
2,613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. server = smtplib.SMTP_SSL('smtp.mail.ru', 465)
  2. server.login(fromaddr, mypass)
  3.  
  4. def send_mail(toaddr, subjectText, bodyText, filesToAttach=[]):
  5. msg = MIMEMultipart()
  6. msg['From'] = fromaddr
  7. msg['To'] = toaddr
  8. msg['Subject'] = subjectText
  9. body = bodyText
  10. msg.attach(MIMEText(body, 'plain'))
  11.  
  12. files=filesToAttach
  13. for f in files or []:
  14. with open(f, "rb") as fil:
  15. part = MIMEApplication(
  16. fil.read(),
  17. Name=basename(f)
  18. )
  19.  
  20. part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
  21. msg.attach(part)
  22.  
  23. text = msg.as_string()
  24. server.sendmail(fromaddr, toaddr, text)
  25.  
  26. server.quit()
Add Comment
Please, Sign In to add comment