Server.sendmail with no "to_addrs" parameter.

E

EdWhyatt

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 "SMTPRecipientsRefused" 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 SMTPRecipientsRefused(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 "(e-mail address removed)" .

Any help would be greatly received.

Cheers
Ed
 
A

Arne Ludwig

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

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

EdWhyatt

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.
 
D

Dennis Lee Bieber

So it's a restriction of Python?
RFC822 is the /standard/ (well, there are newer versions -- 2822?)
for email... It is not Python specific.
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.

Technically, then -- Outlook is in violation of the standard (you
expected Microsoft to be following standards?)
--
 
J

Jeffrey Froman

EdWhyatt said:
I would like to have the ability to send a mail
message with no-one email address in the To field.

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
 
E

EdWhyatt

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
 
J

Jeffrey Froman

EdWhyatt said:
But are you serious about that RFC Compliant thing?

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
 
J

Jim Segrave

RFC822 is the /standard/ (well, there are newer versions -- 2822?)
for email... It is not Python specific.


Technically, then -- Outlook is in violation of the standard (you
expected Microsoft to be following standards?)

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.
 
J

Jim Segrave

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 ;-)

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
 
T

Tim Roberts

EdWhyatt said:
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!

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.sendmail 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: (e-mail address removed)
Subject: This is the RFC-822 part

Hello, mom!"""

s = smtplib.SMTP('localhost')
s.sendmail( "(e-mail address removed)", ["(e-mail address removed)","(e-mail address removed)"], 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: <[email protected]>
RCPT TO: <[email protected]>
RCPT TO: <[email protected]>
DATA
To: (e-mail address removed)
Subject: This is the RFC-822 part

Hello, mom!
.

Those first four commands are SMTP, generated from the first two parameters
to sendmail, and those are the ONLY things that determine where this
message will be delivered. The are called the "envelope". Note that the
actual recipients' names do not appear in the message body AT ALL. At the
other end, Mr. One at Foo, Inc., might be surprised to receive a message
that does not appear to have been addressed to him, but SMTP doesn't care.

So, the way a BCC works is that the address goes into the envelope (in the
to_addrs list), but not in the message body.
 
A

Arne Ludwig

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::sendmail 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.
 

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,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top