943,185 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 6860
  • Python RSS
Jul 23rd, 2008
0

send email in python

Expand Post »
i have a python script and would like to know how to email the output of the script in python.
i can do it from the command line(kshell) with in *nix but would like something like this in the script.
somescript.py; echo "test" | mailx john_smith@xyz.com
Similar Threads
axn
Reputation Points: 10
Solved Threads: 0
Light Poster
axn is offline Offline
39 posts
since Sep 2007
Jul 23rd, 2008
0

Re: send email in python

A very crude method would be to capture your output, and then execute the same command via os.system or a similar call.

Alternately you could make use of smtplib to send the email to a mail server's listener, and send it that way.
Example of using smtplib.
Keep in mind that in this example, the mail listening agent is on the same machine as the script is running. If this is not the case you'll need the ip address and port that the mail daemon is listening on of the server where this service is running.
Last edited by jlm699; Jul 23rd, 2008 at 12:27 pm.
Reputation Points: 355
Solved Threads: 292
Veteran Poster
jlm699 is offline Offline
1,102 posts
since Jul 2008
Jul 23rd, 2008
0

Re: send email in python

Something like the following is a simple example and usually works. If not, then you will have to Google for your specific sendmail app.
Python Syntax (Toggle Plain Text)
  1. fromaddr = "<me@localhost>"
  2. toaddrs = "<you@localhost>"
  3. msg = "Test of Python's sendmail\n"
  4.  
  5. # The actual mail send part
  6. server = smtplib.SMTP('localhost')
  7. server.set_debuglevel(1)
  8. server.sendmail(fromaddr, toaddrs, msg)
  9. print server.verify( toaddrs )
  10. server.quit()
Reputation Points: 738
Solved Threads: 690
Nearly a Posting Maven
woooee is offline Offline
2,295 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Defult (startup) Variables?
Next Thread in Python Forum Timeline: webbrowser.open() opens absolute path +URL instead of URL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC