Server.sendmail with no "to_addrs" parameter.

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

    #1

    Server.sendmail with no "to_addrs" parameter.

    Hi all, I have searched the group with no answer to this particular
    problem.

    In my sendmail program, I would like to have the ability to send a mail
    message with no-one email address in the To field.

    I do this by adding the mail to the CC field via a header. However, by
    the time I get to the point of sending the mail, my recipient list is
    now empty, so I get the "SMTPRecipients Refused" error.

    Looking at smtplib.py, this error is raised by:
    if len(senderrs)== len(to_addrs):
    # the server refused all our recipients
    self.rset()
    raise SMTPRecipientsR efused(senderrs )

    So, being a "fool" I removed this check. I then got the next error, as
    self.data(msg) had unexpected data.

    Can anyone suggest how I can get round this? I have attempted numerous
    things, like making my recipient list = [''], but Exchange then tried
    to send the mail to "none@mydomain. local" .

    Any help would be greatly received.

    Cheers
    Ed

  • Arne Ludwig

    #2
    Re: Server.sendmail with no "to_addrs& quot; parameter.

    > Can anyone suggest how I can get round this? I have attempted numerous[color=blue]
    > things, like making my recipient list = [''], but Exchange then tried
    > to send the mail to "none@mydomain. local" .[/color]

    rfc822: Note that the "Bcc" field may be empty, while the "To"
    field
    rfc822: is required to have at least one address.

    Comment

    • EdWhyatt

      #3
      Re: Server.sendmail with no "to_addrs& quot; parameter.

      So it's a restriction of Python?

      What I am trying to simulate here is the sending of mail to addresses
      solely in the CC and/or BCC fields - both of which are possible through
      Outlook.

      Comment

      • Jeffrey Froman

        #4
        Re: Server.sendmail with no "to_addrs& quot; parameter.

        EdWhyatt wrote:
        [color=blue]
        > I would like to have the ability to send a mail
        > message with no-one email address in the To field.[/color]

        The to_addrs parameter is for the SMTP "RCPT TO", which must contain at
        least one address. It has nothing to do with the To: header of the email.

        You can *also* add the recipient addresses to either of the Cc: or To:
        header fields as necessary, or leave them out of any header (the equivalent
        of adding the addresses to the Bcc: field.)

        As Arne Ludwig pointed it, it may not be RFC compliant to leave an entirely
        blank To: header, but in either case, the To: header need not contain any
        of the addresses specified in the to_addrs list.


        Jeffrey

        Comment

        • EdWhyatt

          #5
          Re: Server.sendmail with no "to_addrs& quot; parameter.

          Ok, totally unrelated, and on that subject, I will make sure I always
          have a recipient in the To: field. - hey it works if I do that anyway!

          But are you serious about that RFC Compliant thing? Can anyone shed
          anymore light on this? I cannot believe that (regardless of our
          opinions of them) Microsoft would allow this (un)knowingly!

          Thanks to all for their comments.

          Cheers
          Ed

          Comment

          • Jeffrey Froman

            #6
            Re: Server.sendmail with no "to_addrs& quot; parameter.

            EdWhyatt wrote:
            [color=blue]
            > But are you serious about that RFC Compliant thing?[/color]

            RFC 2822 obsoletes RFC 822, and I don't know of any specification in RFC
            2822 that requires an email address to be present in the To: header. My
            mail seems to generally work fine without a To: header.

            I haven't memorized RFC 2822 though, so you may want to read it yourself if
            you're concerned ;-)


            Jeffrey

            Comment

            • Jim Segrave

              #7
              Re: Server.sendmail with no "to_addrs& quot; parameter.

              In article <qq0322to837ap4 b6eo4m9uh5krn9e khsf3@4ax.com>,
              Dennis Lee Bieber <wlfraed@ix.net com.com> wrote:[color=blue]
              >On 22 Mar 2006 08:31:16 -0800, "EdWhyatt" <ed.whyatt@gmai l.com>
              >declaimed the following in comp.lang.pytho n:
              >[color=green]
              >> So it's a restriction of Python?
              >>[/color]
              > RFC822 is the /standard/ (well, there are newer versions -- 2822?)
              >for email... It is not Python specific.
              >[color=green]
              >> What I am trying to simulate here is the sending of mail to addresses
              >> solely in the CC and/or BCC fields - both of which are possible through
              >> Outlook.[/color]
              >
              > Technically, then -- Outlook is in violation of the standard (you
              >expected Microsoft to be following standards?)[/color]

              RFC822 and its followup 2822 do not require a To: address line in the
              headers - rfc2822 has the minimum number listed as 0

              There is a difference between the SMTP time recipient address list
              (RCPT TO:) which detemines what the receiving MTA should do with the
              message and the email header To:/CC:/Bcc: lines, which don't (or
              should not in any working system) affect mail routing at all. You
              can't get mail delivered via SMTP without a RCPT TO command at SMTP
              time. Many programs extract this address, in the absence of some other
              means of specifying it, by taking the addresses from the To:, CC: and
              Bcc: headers, but that's a programming convenience, not an RFC
              requirement. Since most people composing emails would find it annoying
              to have to enter the RCPT TO addresses separately, the message
              composition builds header lines, then sends the message to an MTA
              using those addresses. But consider bouncing a mail - then the
              desintation for SMTP is the address you are bouncing the mail to, and
              the header lines are unchanged (one hopes, if not, replace your mail client)

              Much as it pains me to admit it, Outlook, for all its many faults is
              correct if it allows sending messages where the To: CC: and or Bcc:
              headers are empty.


              --
              Jim Segrave (jes@jes-2.demon.nl)

              Comment

              • Jim Segrave

                #8
                Re: Server.sendmail with no &quot;to_addrs& quot; parameter.

                In article <12236cqqf20gc7 f@corp.supernew s.com>,
                Jeffrey Froman <jeffrey@fro.ma n> wrote:[color=blue]
                >EdWhyatt wrote:
                >[color=green]
                >> But are you serious about that RFC Compliant thing?[/color]
                >
                >RFC 2822 obsoletes RFC 822, and I don't know of any specification in RFC
                >2822 that requires an email address to be present in the To: header. My
                >mail seems to generally work fine without a To: header.
                >
                >I haven't memorized RFC 2822 though, so you may want to read it yourself if
                >you're concerned ;-)
                >[/color]

                From RFC 2822:

                The following table indicates limits on the number of times each
                field may occur in a message header as well as any special
                limitations on the use of those fields. An asterisk next to a
                value
                in the minimum or maximum column indicates that a special
                restriction
                appears in the Notes column.

                Field Min number Max number Notes
                ....
                to 0 1

                cc 0 1

                bcc 0 1

                ....


                So the answere is, that it's not required to have any destinations
                listed in the headers of the message.

                It appears that it's not kosher to have an empty To: header, though
                I think that few MUAs will balk at this


                --
                Jim Segrave (jes@jes-2.demon.nl)

                Comment

                • Tim Roberts

                  #9
                  Re: Server.sendmail with no &quot;to_addrs& quot; parameter.

                  "EdWhyatt" <ed.whyatt@gmai l.com> wrote:[color=blue]
                  >
                  >Ok, totally unrelated, and on that subject, I will make sure I always
                  >have a recipient in the To: field. - hey it works if I do that anyway![/color]

                  OK, I'm a bit concerned that the answer to the original question has been
                  lost. The difference between the SMTP envelope and the message content is
                  an important one, and that's the key point here. If this is obvious to
                  everyone involved, I apologize.

                  The actual content of an e-mail message, including the message headers, has
                  absolute nothing to do with the delivery of the message. That's all just a
                  convention that we have developed to allow messages to be read by humans.
                  All of the To:, Cc:, and Bcc: headers are there for you, the human (well,
                  and your helper, the e-mail reader). SMTP doesn't care one whit about
                  them.

                  The smtplib.sendmai l method has three parameters: sender, recipient list,
                  and content. SMTP could not care less about the content. You can skip ALL
                  of the headers (as long as you leave a blank line), and it will be
                  delivered just fine. It won't be RFC 822 compliant, but SMTP doesn't care.
                  SMTP is RFC 821. Your message will get delivered, although the recipients
                  e-mail reader might croak on it.

                  SMTP cares about the sender and the recipient list. Going off the deep
                  end, consider this Python snippet:

                  msg = """\
                  To: noone@nowhere.c om
                  Subject: This is the RFC-822 part

                  Hello, mom!"""

                  s = smtplib.SMTP('l ocalhost')
                  s.sendmail( "tim@go.com ", ["one@foo.com"," two@foo.com"], msg )

                  Note that the To: address is not listed in the sendmail parameters. Now,
                  here is a "simulated" SMTP script for this message:

                  MAIL FROM: <timr@probo.com >
                  RCPT TO: <one@foo.com>
                  RCPT TO: <two@foo.com>
                  DATA
                  To: noone@nowhere.c om
                  Subject: This is the RFC-822 part

                  Hello, mom!

                  Comment

                  • Arne Ludwig

                    #10
                    Re: Server.sendmail with no &quot;to_addrs& quot; parameter.

                    Sorry to have caused all that confusion. The quote from RFC822 I gave
                    is really confusing and is indeed not relevant to the original
                    question. As Tim pointed out, the "to_addrs" parameter in
                    smtplib.py::sen dmail is translated to the SMTP RCPT TO and thus must
                    contain all the intended recipients whether they are logically To, CC,
                    Bcc. That parameter cannot be empty, and that is not a restriction in
                    Python, but a restriction of the nature of email: No recipient, no
                    transmission.

                    It is true that even with RFC 822 it was allowed to have NO To: line,
                    but NOT an empty To: line, while it was allowable to have an empty Bcc:
                    line. This was the quote I gave.

                    Comment

                    Working...