I'm beginning the process of writing an automatic mailer from my server that will send me processes, and whatever else I want. Here is the code:
Code:
import smtplib
def Mailer(argument):
FROMADDR = "fromme@fromme.com"
LOGIN = FROMADDR
PASSWORD = "password"
TOADDRS = ["send@send.com"]
SUBJECT = "Test"
msg = argument
server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(LOGIN, PASSWORD)
server.sendmail(FROMADDR, TOADDRS, msg)
server.quit()
Saved the module as mail.py. Now if argument is a string created on the fly, or if it is a short string written from another program, say:
Code:
import mail
b = 'hello world'
mail.Mailer(b)
it sends perfectly fine. However if i run an exteral command, pipe the output to a file, read the file and send the resulting string as 'argument', nothing happens.
Code:
import os
import mail
a = os.popen2('ps -A > /home/user/info.txt')
b = open('/home/user/info.txt').read()
mail.Mailer(a)
I don't get a traceback or anything. As a matter of fact it shows as if the string was being sent successfully.
Any ideas?
Bookmarks