Changeset 11585 for main/waeup.kofa/trunk/src/waeup/kofa
- Timestamp:
- 10 Apr 2014, 12:57:45 (11 years ago)
- 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 52 52 from zope.sendmail.interfaces import IMailDelivery 53 53 from waeup.kofa.interfaces import IMailService 54 55 56 #: The hardcoded from address. Must not by yahoo.com. 57 FROM_ADDRESS = 'no-reply@waeup.org' 54 58 55 59 … … 158 162 subject, body, config=None): 159 163 """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 160 178 """ 161 179 # format message … … 165 183 body_to += '%s, ' % encode_address(email, rcpt_name) 166 184 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 168 188 body["To"] = body_to.strip(', ') 189 body["Cc"] = body["Reply-To"] = reply_addr 169 190 body["Subject"] = encode_header_item(subject) 170 191 -
main/waeup.kofa/trunk/src/waeup/kofa/tests/test_smtp.py
r10855 r11585 56 56 # 57 57 58 58 59 def external_mail_test(func): 59 60 if not EXTERNAL_MAIL_TESTS: … … 65 66 return 66 67 return func 68 67 69 68 70 class HelperTests(unittest.TestCase): … … 86 88 # we can correctly encode address parts 87 89 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') 89 91 result3 = encode_address('foo@bar.baz', u'The Foo') 90 92 result4 = encode_address('foo@bar.baz', u'With Umläut') … … 141 143 # they contain chars unrepresentable in ascii but available in latin1 142 144 text = u"Simple text with ü and capital pi: " + unichr(0x3a0) 143 text = text.encode('utf-8') # turn unicode into byte stream145 text = text.encode('utf-8') # turn unicode into byte stream 144 146 result1 = encode_body(text) 145 147 result1 = str(result1).split('\n')[1:] … … 173 175 u"Simple text with ü and capital pi: " + unichr(0x3a0)) 174 176 return 177 175 178 176 179 class FunctionalMailerTests(FunctionalTestCase): … … 233 236 self.assertEqual( 234 237 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:', 236 240 u'Message:', 237 241 u'msg: MIME-Version: 1.0', 238 242 u'msg: Content-Type: text/plain; charset="us-ascii"', 239 243 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>', 241 246 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>', 243 248 u'msg: Subject: A subject', 244 249 u'msg: ', … … 258 263 self.assertEqual( 259 264 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:', 261 267 u'Message:', u'msg: MIME-Version: 1.0', 262 268 u'msg: Content-Type: text/plain; charset="iso-8859-1"', 263 269 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>', 265 272 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>', 267 274 u'msg: Subject: A subject', 268 275 u'msg: ', … … 282 289 self.assertEqual( 283 290 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:', 285 293 u'Message:', u'msg: MIME-Version: 1.0', 286 294 u'msg: Content-Type: text/plain; charset="iso-8859-1"', 287 295 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>', 289 298 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>', 291 300 u'msg: Subject: A subject', 292 301 u'msg: ', … … 337 346 ) 338 347 import transaction 339 transaction.commit() # The mail is really sent when transactions is340 # committed348 transaction.commit() # The mail is really sent when transactions is 349 # committed 341 350 self.assertTrue('@' in result) 342 351 return … … 355 364 ) 356 365 import transaction 357 transaction.commit() # The mail is really sent when transactions is358 # committed366 transaction.commit() # The mail is really sent when transactions is 367 # committed 359 368 self.assertTrue('@' in result) 360 369 return … … 372 381 ) 373 382 import transaction 374 transaction.commit() # The mail is really sent when transactions is375 # committed383 transaction.commit() # The mail is really sent when transactions is 384 # committed 376 385 self.assertTrue('@' in result) 377 386 return
Note: See TracChangeset for help on using the changeset viewer.