On Mon, Apr 13, 2009 at 6:55 PM, George Wahid <geoter...@gmail.com> wrote:
> I want to send an email from a google mail account so that the sender
> name will be 'User Name' instead of 'usern...@gmail.com' in the inbox.
> this is the code I use:         (I'm using python 2.5)
>>>>import smtplib
>>>>g=smtplib.SMTP('smtp.googlemail.com')
>>>>g.ehlo();g.starttls();g.ehlo()
>>>>g.login('usern...@gmail.com','somepassword')
>>>>g.sendmail('User Name','usern...@gmail.com','From: User Name\r\nTo: 
>>>>usern...@gmail.com\r\nsubject: how r u ?\r\nfoobar')
> {}
>>>>g.quit()
>
> but this doesn't work, what should I do ?

The first two arguments to sendmail() are the from address and the to
address. Also the From: part of the body should be a valid address. I
think you want something like

g.sendmail('George Wahid <geoter...@gmail.com>',
'User Name <usern...@gmail.com>',
'From: George Wahid <geoter...@gmail.com>\r\nTo: User Name
<usern...@gmail.com>\r\nSubject: how r u ?\r\nfoobar')

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to