emai - Multiple recipenets in "To:"
Larry Bates
lbates at swamisoft.com
Tue Mar 9 14:49:58 EST 2004
Normally 2nd and subsequent people to get
email should go in the CC: (or BCC:) field
but apparently you can do it by putting a
newline at the end of each entry in the
To: field.
See suggested change in your code below.
-Larry
"Miki Tebeka" <miki.tebeka at zoran.com> wrote in message
news:c2l3g5$h0f$1 at news2.netvision.net.il...
> Hello All,
>
> Our nightly build system is supposed to send email notification on build
> status to several developers. Using SMTP and email packages I can post
> email to one user at a time, then I try to add multiple email addresses
> in the "To" field only the 1'st person gets the email.
>
> A lot of this code is taken from the email demo.
> ---
> VERBOSE = False
> def inform(msg):
> if not VERBOSE:
> return
> print "*", msg
> stdout.flush()
>
> def sendmail(msg, to, attachments=None, **kw):
> '''Send email
> msg - Message
> to - To address
> attachments - List of files to attach
> kw - Other keyword arguments
> '''
> main = MIMEMultipart()
> subject = kw.get("subject", "Email Message")
> inform("Subject = %s" % subject)
> main["Subject"] = subject
> _from = kw.get("from","%s at zoran.co.il" % getuser())
> inform("From = %s" % _from)
> main["From"] = _from
I think you can also change the following line,
At least that is how the code in the SmtpWriter.py
module I use does it.
> to = ",\n ".join(list(to))
> inform("To = %s" % to)
> main["To"] = to
> main.epilogue = ""
>
> main.attach(MIMEText(msg))
> if attachments:
> for path in attachments:
> if not isfile(path):
> continue
> # Guess the content type based on the file"s extension.
> # Encoding
> # will be ignored, although we should check for simple
> # things like
> # gzip"d or compressed files.
> ctype, encoding = guess_type(path)
> if ctype is None or encoding is not None:
> # No guess could be made, or the file is encoded
> # (compressed), so
> # use a generic bag-of-bits type.
> ctype = "application/octet-stream"
> maintype, subtype = ctype.split("/", 1)
> if maintype == "text":
> inform("Attaching %s as text file" % path)
> fp = open(path)
> # Note: we should handle calculating the charset
> msg = MIMEText(fp.read(), _subtype=subtype)
> fp.close()
> elif maintype == "image":
> inform("Attaching %s as image file" % path)
> fp = open(path, "rb")
> msg = MIMEImage(fp.read(), _subtype=subtype)
> fp.close()
> elif maintype == "audio":
> inform("Attaching %s as audio file" % path)
> fp = open(path, "rb")
> msg = MIMEAudio(fp.read(), _subtype=subtype)
> fp.close()
> else:
> inform("Attaching %s as generic file [%s]" % \
> (path, ctype))
> fp = open(path, "rb")
> msg = MIMEBase(maintype, subtype)
> msg.set_payload(fp.read())
> fp.close()
> # Encode the payload using Base64
> encode_base64(msg)
> # Set the filename parameter
> msg.add_header("Content-Disposition", "attachment",
> filename=basename(path))
> main.attach(msg)
> s = SMTP()
> server = kw.get("server", "mail.zoran.co.il")
> inform("Connecting to %s..." % server)
> s.connect(server)
> msgstr = main.as_string()
> inform("Sending %d bytes..." % len(msgstr))
> s.sendmail(main["From"], main["To"], msgstr)
> s.close()
> ---
>
> Thanks.
> Miki
More information about the Python-list
mailing list