module email

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

    #1

    module email

    Hello.

    Why does not work?

    --------------
    import email.message
    import smtplib
    import time

    m=email.message .Message()
    m.set_type("mul tipart/mixed")
    m["From"]="Sergey Dorofeev <sergey@prodo.r u>"
    m["To"]="Sergey Dorofeev <sergey@prodo.r u>"
    m["Date"]=time.asctime()
    m["Subject"]="test"


    p1=email.messag e.Message()
    p1.set_payload( "message text", "us-ascii")
    m.attach(p1)

    p2=email.messag e.Message()
    p2.set_payload( "message text 2", "us-ascii")
    m.attach(p2)

    del p1,p2

    print m.as_string()
    print "*"*50


    x=email.message .Message()
    x.set_type("mul tipart/mixed")
    x["From"]="Sergey Dorofeev <sergey@prodo.r u>"
    x["To"]="Sergey Dorofeev <sergey@prodo.r u>"
    x["Date"]=time.asctime()
    x["Subject"]="test"

    p1=email.messag e.Message()
    p1.set_payload( "message text !", "us-ascii")
    print p1
    x.attach(p1)


    p2=email.messag e.Message()
    p2.set_type("me ssage/rfc822")
    p2.set_payload( m)
    print p2
    x.attach(p2)


    print "*"*50
    print x.as_string()

    --------------

    I'm using Python 2.5


  • Gabriel Genellina

    #2
    Re: module email

    At Wednesday 24/1/2007 13:02, Sergey Dorofeev wrote:
    >Why does not work?
    Some details please?


    --
    Gabriel Genellina
    Softlab SRL






    _______________ _______________ _______________ _____
    Preguntá. Respondé. Descubrí.
    Todo lo que querías saber, y lo que ni imaginabas,
    está en Yahoo! Respuestas (Beta).
    ¡Probalo ya!


    Comment

    • Rob Wolfe

      #3
      Re: module email

      "Sergey Dorofeev" <sergey@fidoman .ruwrites:
      Hello.
      >
      Why does not work?
      [...]
      m=email.message .Message()
      [...]
      p2=email.messag e.Message()
      p2.set_type("me ssage/rfc822")
      p2.set_payload( m)
      Payload is a _list_ of Message objects (is_multipart() == True)
      or a _string_ object (is_multipart() == False) but never just Message object.

      Source code: Lib/email/message.py The central class in the email package is the EmailMessage class, imported from the email.message module. It is the base class for the email object model. EmailMes...


      --
      HTH,
      Rob

      Comment

      • Sergey Dorofeev

        #4
        Re: module email


        "Rob Wolfe" <rw@smsnet.plwr ote in message news:874pqgf7hb .fsf@smsnet.pl. ..
        >p2=email.messa ge.Message()
        >p2.set_type("m essage/rfc822")
        >p2.set_payload (m)
        >
        Payload is a _list_ of Message objects (is_multipart() == True)
        or a _string_ object (is_multipart() == False) but never just Message
        object.
        1. If I give m.as_string() into set_payload, result is the same.
        2. I don't understand, how message/rfc822 section can accept a list of two
        or more messages. Can you explain?


        Comment

        • Rob Wolfe

          #5
          Re: module email


          Sergey Dorofeev wrote:
          "Rob Wolfe" <rw@smsnet.plwr ote in message news:874pqgf7hb .fsf@smsnet.pl. ..
          >
          p2=email.messag e.Message()
          p2.set_type("me ssage/rfc822")
          p2.set_payload( m)
          Payload is a _list_ of Message objects (is_multipart() == True)
          or a _string_ object (is_multipart() == False) but never just Message
          object.
          >
          1. If I give m.as_string() into set_payload, result is the same.
          The payload of a message/rfc822 is treated like a sequence
          of length 1. So that works:
          p2.set_payload([m])
          2. I don't understand, how message/rfc822 section can accept a list of two
          or more messages. Can you explain?
          That's another question.
          I don't understand either, why the payload for message/rfc822 has to be
          a list of length 1 and not a Message object itself.
          This assumption looks strange to me, too, but I can live with that. :)

          --
          Regards,
          Rob

          Comment

          Working...