send email in python

Reply

Join Date: Sep 2007
Posts: 25
Reputation: axn is an unknown quantity at this point 
Solved Threads: 0
axn axn is offline Offline
Light Poster

send email in python

 
0
  #1
Jul 23rd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,041
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 261
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: send email in python

 
0
  #2
Jul 23rd, 2008
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.
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 995
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 281
woooee woooee is offline Offline
Posting Shark

Re: send email in python

 
0
  #3
Jul 23rd, 2008
Something like the following is a simple example and usually works. If not, then you will have to Google for your specific sendmail app.
  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()
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC