send email

Peter Nuttall pnu at
Thu Sep 25 17:55:44 CEST 2003

On Thursday 25 Sep 2003 2:45 pm, Alberto Vera wrote:
> Thanks for your reply.
> I'd like to explain the problem to get a better idea about this.
> A python program check every minute if a value is 0 in a register on a
> database. In this case using Python, it'll send an email.

I am not sure how to do the checking part but the email part would look like 

# this module is for sending email
import smtplib

#this module is needed for making message-IDs

#change message string to the message you want
#no longer than 78 letters

message = 'test message'

#adds headers to email

#change these to what you want
fromaddr=raw_input('what is the from address ')
toaddrs=raw_input('what is the to address ')
subject=raw_input('what is the subject ')
sever=raw_input('what is the smtp sever you are using ')
timesend=strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
#msg-id maker
#change lupin to the name of your computer

while x<5:
msg_id = msg_id + '@lupin'

finalmessage = 'From: '+fromaddr +'\r\n'+ 'To: '+toaddrs 
finalmessage = finalmessage +'\r\n'+ 'Subject: '+ subject +'\r\n' + 'Date: ' + 
finalmessage = finalmessage + '\r\n' +'Message-ID: ' + msg_id + '\r\n' + '\r
\n' +message

#code for sending email
server = smtplib.SMTP(sever)
server.sendmail(fromaddr, toaddrs, finalmessage)
this code is chunky and will need changing to just what you want. 

look at the smtplib docs, the rfc2822 standard (email), and what Riccardo 
Galli had to say about my email program

Someone esle can help you better than I can.

Every time I think that perhaps we are an advanced race, I turn around and 
read ramblings on Slashdot, and realize I was wrong.

More information about the Python-list mailing list