Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def send_mail(send_from, send_to, subject, text, files=None, server="mail.directservices.bg"):
- assert isinstance(send_to, list)
- username = ''
- password = ''
- msg = MIMEMultipart()
- msg['From'] = send_from
- msg['To'] = COMMASPACE.join(send_to)
- msg['Date'] = formatdate(localtime=True)
- msg['Subject'] = subject
- msg.attach(MIMEText(text.encode('utf-8'), 'html', 'utf-8'))
- for f in files or []:
- with open(f, "rb") as fil:
- part = MIMEApplication(
- fil.read(),
- Name=basename(f)
- )
- # After the file is closed
- part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
- msg.attach(part)
- smtp = smtplib.SMTP(server)
- smtp.ehlo()
- smtp.starttls()
- smtp.login(username, password)
- smtp.sendmail(send_from, send_to, msg.as_string())
- smtp.close()
- 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