purpleflame
New Member
- Messages
- 17
- Reaction score
- 0
- Points
- 0
I am interested in making a cron job that will send email. So to start off with I am making a script to send an email with a python script. I found a couple different ways to do this -- using sendmail and smtplib. I tried using the sendmail method with this script but I do not know where it went wrong.
I get an Internal Server Error 500. When I look at my error logs the only new listing is:
What is odd is that I also made one to test sending with smtplib. This script does the same thing but also sends the email. Odd f
Any ideas?
Code:
# This script is to test using the sendmail pipe to send emails.
#!/usr/bin/env python
print "Content-type: text/plain"
print
import os
MAIL = "/usr/sbin/sendmail"
# Read the email message from a file.
f = open('sampleemail.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:
[Mon Apr 06 19:46:53 2009] [error] [client 141.217.222.214] File does not exist: /home/pf/public_html/500.shtml
Code:
#!/usr/bin/env python
import smtplib
SERVER = "localhost"
FROM = "purple@purpleflame.exofire.net"
TO = ["alikakakhel@yahoo.com"] # must be a list
SUBJECT = "Testing..."
TEXT = "...working"
# Prepare actual message
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# Send the mail
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()