Skip to content

Instantly share code, notes, and snippets.

@iorionda
Created May 22, 2012 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iorionda/2767379 to your computer and use it in GitHub Desktop.
Save iorionda/2767379 to your computer and use it in GitHub Desktop.
send email and not use smtplib and email
#!/usr/local/bin/python
# -*- coding:utf-8 -*-
import os
SENDMAIL_LOCATION = "/var/qmail/bin/sendmail"
def send(sender, receivers, subject, body, encoding):
p = os.popen("%s -t" % SENDMAIL_LOCATION, "w")
p.write("From: %s\n" % sender)
p.write("Reply-to: %s\n" % sender)
p.write("To: %s\n" % ','.join(receivers))
p.write("Content-type: text/html\n")
p.write("Subject: %s\n" % subject.encode(encoding))
p.write("\n")
p.write(body.encode(encoding))
p.close()
if __name__ == '__main__':
sender = 'from@xxxx'
receivers = ['to@xxxx']
subject = u'テスト件名'
body = u'テスト本文'
encoding = 'utf-8'
send(sender, receivers, subject, body, encoding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment