smtplib - missing message

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alastair

    smtplib - missing message

    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.yaho o.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("s mtp.mail.yahoo. com")
    server.debuglev el = 25
    server.login("m yusername", "mypassword ")

    fromClause = "me@me.com"
    toClause = "you@yahoo.co.u k"

    msg = "Please display me."

    server.sendmail (fromClause, toClause, msg)

    server.quit()

    Regards,

    Alastair.
  • Peter Hansen

    #2
    Re: smtplib - missing message

    alastair wrote:
    [color=blue]
    > 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 = "you@yahoo.co.u k"
    >
    > msg = "Please display me."
    >
    > server.sendmail (fromClause, toClause, msg)[/color]

    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

    Comment

    • Mathias Waack

      #3
      Re: smtplib - missing message

      Peter Hansen wrote:
      [color=blue]
      > msg = "Subject: test\n\nPlease display me."[/color]

      Better use the mime classes from package "email":

      msg = MIMEText("Pleas e display me.").as_string ()

      Mathias

      Comment

      • alastair

        #4
        Re: smtplib - missing message

        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.

        Comment

        Working...