smtplib - missing message

A

alastair

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 = "(e-mail address removed)"
toClause = "(e-mail address removed)"

msg = "Please display me."

server.sendmail(fromClause, toClause, msg)

server.quit()

Regards,

Alastair.
 
P

Peter Hansen

alastair said:
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 = "(e-mail address removed)"
toClause = "(e-mail address removed)"

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
 
M

Mathias Waack

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

Better use the mime classes from package "email":

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

Mathias
 
A

alastair

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top