Ignore:
Timestamp:
10 Apr 2014, 12:57:45 (11 years ago)
Author:
uli
Message:

When sending mail, use waeup.org address for from-field.

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

Legend:

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

    r11584 r11585  
    5252from zope.sendmail.interfaces import IMailDelivery
    5353from waeup.kofa.interfaces import IMailService
     54
     55
     56#: The hardcoded from address. Must not by yahoo.com.
     57FROM_ADDRESS = 'no-reply@waeup.org'
    5458
    5559
     
    158162              subject, body, config=None):
    159163    """Send mail.
     164
     165    Use `IMailService` to send a mail with the parameters
     166    delivered.
     167
     168    Please note: the `from_addr` given will be used for the reply-to
     169    and cc field only. It will _not_ be used for the `from` field, as
     170    yahoo does not allow non-yahoo servers to deliver mail with
     171    ``@yahoo.com`` in the from-field.
     172
     173    The from-address set here will be: `FROM_ADDRESS` as set above.
     174
     175    XXX: The hard-coded from-address should be changable or be
     176         determined smarter by looking up a FQDN or similar.
     177
    160178    """
    161179    # format message
     
    165183        body_to += '%s, ' % encode_address(email, rcpt_name)
    166184    body = encode_body(body)
    167     body["From"] = body["Cc"] = encode_address(from_addr, from_name)
     185    sender_addr = encode_address(FROM_ADDRESS, from_name)
     186    reply_addr = encode_address(from_addr, from_name)
     187    body["From"] = sender_addr
    168188    body["To"] = body_to.strip(', ')
     189    body["Cc"] = body["Reply-To"] = reply_addr
    169190    body["Subject"] = encode_header_item(subject)
    170191
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_smtp.py

    r10855 r11585  
    5656#
    5757
     58
    5859def external_mail_test(func):
    5960    if not EXTERNAL_MAIL_TESTS:
     
    6566        return
    6667    return func
     68
    6769
    6870class HelperTests(unittest.TestCase):
     
    8688        # we can correctly encode address parts
    8789        result1 = encode_address('foo@bar.baz')
    88         result2 = encode_address(u'foo@bar.baz', 'The Foo' )
     90        result2 = encode_address(u'foo@bar.baz', 'The Foo')
    8991        result3 = encode_address('foo@bar.baz', u'The Foo')
    9092        result4 = encode_address('foo@bar.baz', u'With Umläut')
     
    141143        # they contain chars unrepresentable in ascii but available in latin1
    142144        text = u"Simple text with ü and capital pi: " + unichr(0x3a0)
    143         text = text.encode('utf-8') # turn unicode into byte stream
     145        text = text.encode('utf-8')  # turn unicode into byte stream
    144146        result1 = encode_body(text)
    145147        result1 = str(result1).split('\n')[1:]
     
    173175            u"Simple text with ü and capital pi: " + unichr(0x3a0))
    174176        return
     177
    175178
    176179class FunctionalMailerTests(FunctionalTestCase):
     
    233236        self.assertEqual(
    234237            self.get_fake_smtp_output().split('\n'),
    235             [u'Sending email from sender@example.com to recpt@example.com, sender@example.com:',
     238            [u'Sending email from sender@example.com to '
     239             u'recpt@example.com, sender@example.com:',
    236240             u'Message:',
    237241             u'msg: MIME-Version: 1.0',
    238242             u'msg: Content-Type: text/plain; charset="us-ascii"',
    239243             u'msg: Content-Transfer-Encoding: 7bit',
    240              u'msg: From: A sender <sender@example.com>',
     244             u'msg: From: A sender <no-reply@waeup.org>',
     245             u'msg: To: A recipient <recpt@example.com>',
    241246             u'msg: Cc: A sender <sender@example.com>',
    242              u'msg: To: A recipient <recpt@example.com>',
     247             u'msg: Reply-To: A sender <sender@example.com>',
    243248             u'msg: Subject: A subject',
    244249             u'msg: ',
     
    258263        self.assertEqual(
    259264            self.get_fake_smtp_output().split('\n'),
    260             [u'Sending email from sender@example.com to recpt@example.com, sender@example.com:',
     265            [u'Sending email from sender@example.com '
     266             u'to recpt@example.com, sender@example.com:',
    261267             u'Message:', u'msg: MIME-Version: 1.0',
    262268             u'msg: Content-Type: text/plain; charset="iso-8859-1"',
    263269             u'msg: Content-Transfer-Encoding: quoted-printable',
    264              u'msg: From: A sender <sender@example.com>',
     270             u'msg: From: A sender <no-reply@waeup.org>',
     271             u'msg: To: A recipient <recpt@example.com>',
    265272             u'msg: Cc: A sender <sender@example.com>',
    266              u'msg: To: A recipient <recpt@example.com>',
     273             u'msg: Reply-To: A sender <sender@example.com>',
    267274             u'msg: Subject: A subject',
    268275             u'msg: ',
     
    282289        self.assertEqual(
    283290            self.get_fake_smtp_output().split('\n'),
    284             [u'Sending email from sender@example.com to recpt@example.com, sender@example.com:',
     291            [u'Sending email from sender@example.com '
     292             u'to recpt@example.com, sender@example.com:',
    285293             u'Message:', u'msg: MIME-Version: 1.0',
    286294             u'msg: Content-Type: text/plain; charset="iso-8859-1"',
    287295             u'msg: Content-Transfer-Encoding: quoted-printable',
    288              u'msg: From: A sender <sender@example.com>',
     296             u'msg: From: A sender <no-reply@waeup.org>',
     297             u'msg: To: A recipient <recpt@example.com>',
    289298             u'msg: Cc: A sender <sender@example.com>',
    290              u'msg: To: A recipient <recpt@example.com>',
     299             u'msg: Reply-To: A sender <sender@example.com>',
    291300             u'msg: Subject: A subject',
    292301             u'msg: ',
     
    337346            )
    338347        import transaction
    339         transaction.commit() # The mail is really sent when transactions is
    340                              # committed
     348        transaction.commit()  # The mail is really sent when transactions is
     349                              # committed
    341350        self.assertTrue('@' in result)
    342351        return
     
    355364            )
    356365        import transaction
    357         transaction.commit() # The mail is really sent when transactions is
    358                              # committed
     366        transaction.commit()  # The mail is really sent when transactions is
     367                              # committed
    359368        self.assertTrue('@' in result)
    360369        return
     
    372381            )
    373382        import transaction
    374         transaction.commit() # The mail is really sent when transactions is
    375                              # committed
     383        transaction.commit()  # The mail is really sent when transactions is
     384                              # committed
    376385        self.assertTrue('@' in result)
    377386        return
Note: See TracChangeset for help on using the changeset viewer.