[Tutor] Mailing Made Simple - Multiple Recipient Problem
Karl Pflästerer
sigurd at 12move.de
Tue Jan 6 14:36:34 EST 2004
On 6 Jan 2004, Sean Steeg <- steegness at hotmail.com wrote:
> OK then, just to make sure I grasp what's going on here then:
> Where is the SMTP server getting its recipient information from? That
> is to say, which is parsed to send the letter out to someone?
> smtplib's send function calls for recipients in its argument, outside
> of any headers in the letter itself; I would think it'd be there where
> the recipients are found.
,----[ Python library docu ]
| `sendmail(from_addr, to_addrs, msg[, mail_options, rcpt_options])'
| Send mail. The required arguments are an RFC 822 from-address
| string, a list of RFC 822 to-address strings, and a message string.
`----
So the to_addrs are a list of strings. To send e-mail to multiple
recipients you could write:
In [1]: import smtplib
In [2]: server = smtplib.SMTP('127.0.0.1')
In [3]: msg = """
...: mFrom: me
...: mTo: some people
...: m
...: mbody body body
...: m"""
In [4]: server.sendmail('me', ['admin', 'testeins'], msg)
Out[4]: {}
If I look in the log file of my smtp server I see (logfile is debug
level and all possible checking turned off):
ceb} < 220 SMTP-Server Classic Hamster Version 2.0 (Build 2.0.4.0) on wintendo.pflaesterer.de is ready.
ceb} > ehlo [127.0.0.1]
ceb} < 250-wintendo.pflaesterer.de
ceb} < 250-8BITMIME
ceb} < 250-AUTH DIGEST-MD5 CRAM-SHA1 CRAM-MD5 LOGIN
ceb} < 250-AUTH=DIGEST-MD5 CRAM-SHA1 CRAM-MD5 LOGIN
ceb} < 250 HELP
ceb} > mail FROM:<me>
ceb} < 250 OK
ceb} > rcpt TO:<admin>
ceb} < 250 OK
ceb} > rcpt TO:<testeins>
ceb} < 250 OK
ceb} > data
ceb} < 354 Start mail input; end with <CRLF>.<CRLF>
[...]
ceb} Mailrouter: Mail from <me> delivered to all recipients
ceb} < 250 OK
So for every entry in the list of recipients one RCPT TO is created.
> Let's say I want to switch this around to get multiple recipients. I
> know I can adjust the headers easily enough, so that the multiples are
> CCs instead of TOs, but what should I do with that first argument for
> the smtplib.send() function?
Hope the above helps (I think you mean smtplib.sendmail()).
(please consider to stop top posting; it's hard to read).
Karl
--
Please do *not* send copies of replies to me.
I read the list
More information about the Tutor
mailing list