Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pythonsmtp [2014/10/26 01:52] (current)
Line 1: Line 1:
 +==== Python: Send SMTP message (email) ====
 +
 +{red}This works only on Linux/​Unix/​Solaris{red}
 +
 +<code lang="​python">​
 +#​!/​usr/​bin/​python
 +
 +import os
 +
 +# adjust MAIl as per your system environment
 +MAIL = "/​usr/​sbin/​sendmail"​
 +
 +# get the email message from a file
 +f = open('​mssg.txt',​ '​r'​)
 +mssg = f.read()
 +f.close()
 +
 +# open a pipe to the mail program and
 +# write the data to the pipe
 +p = os.popen("​%s -t" % MAIL, '​w'​)
 +p.write(mssg)
 +exitcode = p.close()
 +if exitcode:
 +        print "Exit code: %s" % exitcode
 +
 +</​code>​
 +  * The message has to be a file
 +<​code>​
 +To: mnain@sender.com
 +From: sysmon@receiver.net
 +Subject: My Test email
 +
 +Here is the message body.
 +This concludes our test.
 +Fini.
 +
 +- sig
 +
 +</​code>​
 +
 +----
 +  * [[pythoninfo|Back to python]]
  
pythonsmtp.txt ยท Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0