By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,996 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,996 IT Pros & Developers. It's quick & easy.

smtplib - missing message

P: n/a
Hi,

I'm trying to send an email using smtplib and a Yahoo smtp server.
I've read that this uses authentication, so in order to use
'smtp.mail.yahoo.com' as the host, I use the login() method, and this
works fine (ie I login ok) . When I look at the received mail, the
text I send is not there - does anyone know why this is the case ?

Here's the code I've been using:

import smtplib

server = smtplib.SMTP("smtp.mail.yahoo.com")
server.debuglevel = 25
server.login("myusername", "mypassword")

fromClause = "me@me.com"
toClause = "yo*@yahoo.co.uk"

msg = "Please display me."

server.sendmail(fromClause, toClause, msg)

server.quit()

Regards,

Alastair.
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
alastair wrote:
I'm trying to send an email using smtplib ....
When I look at the received mail, the
text I send is not there - does anyone know why this is the case ?

Here's the code I've been using:
fromClause = "me@me.com"
toClause = "yo*@yahoo.co.uk"

msg = "Please display me."

server.sendmail(fromClause, toClause, msg)


RFC2822 (or whatever it is) specifies that a mail message has
headers, separated from the body of the message by an extra
newline. (Or is it a CRLF combination? You can look that up
yourself.) You don't have any header in your message, so
you'll have to add one, something like:

msg = "Subject: test\n\nPlease display me."

Note the double newline to mark the end of the header fields.

-Peter
Jul 18 '05 #2

P: n/a
Peter Hansen wrote:
msg = "Subject: test\n\nPlease display me."


Better use the mime classes from package "email":

msg = MIMEText("Please display me.").as_string()

Mathias
Jul 18 '05 #3

P: n/a
Peter - thanks for the information, this did the trick !

Matthias - thanks for pointing out the email module - I'm pretty new
to Python and hadn't discovered it, this'll come in real handy.

Thanks again guys,

Cheers,

Alastair.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.