pnu at ukfsn.org
Thu Sep 25 17:25:18 CEST 2003
On Thursday 25 Sep 2003 2:51 pm, Riccardo Attilio Galli wrote:
> On Thu, 25 Sep 2003 11:46:16 +0100, Peter Nuttall wrote:
> > here is a program to send emails with python. It was writien quickly so
> > it is not perfect.
> > [SNIP]
> > if anyone has any comments I would like to see them.
> peter, your program write 'e-mail' absolutely not rfc2822 compliant.
Yeah, I thought It was not compliant. Thanks for the weblink. I have changed
it based on the standard and what you said, but I have a few questions:
1. message-ID: I have written an few lines of code that have the date and time
on one side of a @ and the computer's name of the other. is that OK?
2. is there a better way to make the date string that the loop that I have?
3. line length: Is having it set to 78 ok or is that 2 over the limit?
Here is the new code:
from time import gmtime, strftime, localtime
message = ''
print 'type message here:'
end = 0
while end == 0:
print 'end of message'
message = message + '\r\n'
while x <= lent:
chop=(x+1) * winth_of_email+x
msg = msg[:chop] + '\r\n' + msg[chop:]
message = message +'\r\n'+ msg
#adds headers to email
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())
#change lupin to the name of your computer
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
print "Message length is " + `len(finalmessage)`
#code for sending email
server = smtplib.SMTP(sever)
server.sendmail(fromaddr, toaddrs, finalmessage)
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