Changeset 9306


Ignore:
Timestamp:
7 Oct 2012, 08:32:45 (12 years ago)
Author:
Henrik Bettermann
Message:

Enable sending emails to several email addresses all the with the same rcpt_name (Import Manager, Clearance Officer ...).

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/smtp.py

    r8382 r9306  
    149149    return MIMEText(text, 'plain', charset)
    150150
    151 def send_mail(from_name, from_addr, rcpt_name, rcpt_addr,
     151def send_mail(from_name, from_addr, rcpt_name, rcpt_addrs,
    152152              subject, body, config=None):
    153153    """Send mail.
    154154    """
    155155    # format message
     156    rcpt_addrs = rcpt_addrs.replace(' ','').split(',')
     157    body_to = ''
     158    for email in rcpt_addrs:
     159        body_to += '%s, ' % encode_address(email, rcpt_name)
    156160    body = encode_body(body)
    157161    body["From"] = encode_address(from_addr, from_name)
    158     body["To"] = encode_address(rcpt_addr, rcpt_name)
     162    body["To"] = body_to.strip(', ')
    159163    body["Subject"] = encode_header_item(subject)
    160164
    161165    mailer = getUtility(IMailService)
    162     result = mailer().send(from_addr, [rcpt_addr], body.as_string())
     166    result = mailer().send(from_addr, rcpt_addrs, body.as_string())
    163167    return result
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9305 r9306  
    11691169        self.assertTrue(
    11701170            'You entered invalid credentials.' in self.browser.contents)
    1171         import pdb; pdb.set_trace()
    11721171        # We set the password again
    11731172        IUserAccount(
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_smtp.py

    r8382 r9306  
    4545# Maybe existing receiver of externally sent mail. If this mail account
    4646# exists really, it might receive mail from the tests!
    47 EXTERNAL_MAIL_RECEIVER = 'no-user@waeup.org'
     47EXTERNAL_MAIL_RECEIVER = 'no-reply@waeup.org'
    4848
    4949# Names of mail deliveries to use when external mail tests are enabled.
     
    340340
    341341    @external_mail_test
     342    def test_send_direct_mails(self):
     343        # send several mails using direct mail delivery
     344        self.app['configuration'].smtp_mailer = EXTERNAL_DIRECT_DELIVERY
     345        setSite(self.app)
     346        result = send_mail(
     347            'test program', 'no-reply@waeup.org',
     348            'test mail receiver',
     349            '%s, %s' % (EXTERNAL_MAIL_RECEIVER, EXTERNAL_MAIL_RECEIVER),
     350            'Test Mail from WAeUP Kofa',
     351            'Hi from test mailer!\n\nRegards,\nTest Programme\n'
     352            )
     353        import transaction
     354        transaction.commit() # The mail is really sent when transactions is
     355                             # committed
     356        self.assertTrue('@' in result)
     357        return
     358
     359    @external_mail_test
    342360    def test_send_queued_mail(self):
    343361        # send mail using queued mail delivery
Note: See TracChangeset for help on using the changeset viewer.