1.1 --- a/imiptools/mail.py Wed Dec 10 17:35:00 2014 +0100
1.2 +++ b/imiptools/mail.py Wed Dec 10 18:42:08 2014 +0100
1.3 @@ -1,6 +1,6 @@
1.4 #!/usr/bin/env python
1.5
1.6 -from imiptools.config import MESSAGE_SENDER
1.7 +from imiptools.config import MESSAGE_SENDER, OUTGOING_PREFIX
1.8 from email.mime.message import MIMEMessage
1.9 from email.mime.multipart import MIMEMultipart
1.10 from email.mime.text import MIMEText
1.11 @@ -27,12 +27,13 @@
1.12 self.body_text = body_text or MESSAGE_TEXT
1.13 self.preamble_text = preamble_text or PREAMBLE_TEXT
1.14
1.15 - def sendmail(self, recipients, data, sender=None, lmtp_socket=None):
1.16 + def sendmail(self, recipients, data, sender=None, outgoing_bcc=None, lmtp_socket=None):
1.17
1.18 """
1.19 Send a mail to the given 'recipients' consisting of the given 'data',
1.20 - using the given 'sender' identity if indicated, delivering to a local
1.21 - mail system using LMTP if 'lmtp_socket' is provided.
1.22 + using the given 'sender' identity if indicated, indicating an
1.23 + 'outgoing_bcc' identity if indicated, delivering to a local mail system
1.24 + using LMTP if 'lmtp_socket' is provided.
1.25 """
1.26
1.27 if lmtp_socket:
1.28 @@ -40,14 +41,18 @@
1.29 else:
1.30 smtp = SMTP("localhost")
1.31
1.32 + if outgoing_bcc:
1.33 + recipients = list(recipients) + ["%s+%s" % (OUTGOING_PREFIX, outgoing_bcc)]
1.34 +
1.35 smtp.sendmail(sender or self.sender, recipients, data)
1.36 smtp.quit()
1.37
1.38 - def make_message(self, parts, recipients, sender=None):
1.39 + def make_message(self, parts, recipients, sender=None, outgoing_bcc=None):
1.40
1.41 """
1.42 Make a message from the given 'parts' for the given 'recipients', using
1.43 - the given 'sender' identity if indicated.
1.44 + the given 'sender' identity if indicated, indicating an 'outgoing_bcc'
1.45 + identity if indicated.
1.46 """
1.47
1.48 message = MIMEMultipart("mixed", _subparts=parts)
1.49 @@ -58,6 +63,8 @@
1.50 message["From"] = sender or self.sender
1.51 for recipient in recipients:
1.52 message["To"] = recipient
1.53 + if outgoing_bcc:
1.54 + message["Bcc"] = "%s+%s" % (OUTGOING_PREFIX, outgoing_bcc)
1.55 message["Subject"] = self.subject
1.56
1.57 return message