@@ -304,17 +304,20 @@ def smtp_error_user_warning(thing,request):
304304 except smtplib .SMTPException as e :
305305 (extype , value , tb ) = log_smtp_exception (e )
306306
307- warning = "An error occured while sending email with\n "
308- warning += "Subject: %s\n " % e .original_msg .get ('Subject' ,'[no subject]' )
309- warning += "To: %s\n " % e .original_msg .get ('To' ,'[no to]' )
310- warning += "Cc: %s\n " % e .original_msg .get ('Cc' ,'[no cc]' )
311- if isinstance (e ,SMTPSomeRefusedRecipients ):
312- warning += e .detailed_refusals ()
313- else :
314- warning += "SMTP Exception: %s\n " % extype
315- warning += "Error Message: %s\n \n " % value
316- warning += "The message was not delivered to anyone."
317- messages .warning (request ,warning ,extra_tags = 'preformatted' ,fail_silently = True )
307+ if request :
308+ warning = "An error occured while sending email:\n "
309+ if (e .original_msg ):
310+ warning += "Subject: %s\n " % e .original_msg .get ('Subject' ,'[no subject]' )
311+ warning += "To: %s\n " % e .original_msg .get ('To' ,'[no to]' )
312+ warning += "Cc: %s\n " % e .original_msg .get ('Cc' ,'[no cc]' )
313+ if isinstance (e ,SMTPSomeRefusedRecipients ):
314+ warning += e .detailed_refusals ()
315+ else :
316+ warning += "SMTP Exception: %s\n " % extype
317+ warning += "Error Message: %s\n \n " % value
318+ warning += "The message was not delivered to anyone."
319+ messages .warning (request ,warning ,extra_tags = 'preformatted' ,fail_silently = True )
320+
318321 raise
319322
320323@contextmanager
@@ -324,68 +327,52 @@ def smtp_error_logging(thing):
324327 except smtplib .SMTPException as e :
325328 (extype , value , tb ) = log_smtp_exception (e )
326329
327- msg = textwrap .dedent ("""\
328- To: <action@ietf.org>
329- From: %s
330- """ ) % settings .SERVER_EMAIL
330+ msg = MIMEMultipart ()
331+ msg ['To' ] = '<action@ietf.org>'
332+ msg ['From' ] = settings .SERVER_EMAIL
331333 if isinstance (e ,SMTPSomeRefusedRecipients ):
332- msg += textwrap .dedent ("""\
333- Subject: Some recipients were refused while sending mail with Subject: %s
334+ msg ['Subject' ] = 'Subject: Some recipients were refused while sending mail with Subject: %s' % e .original_msg .get ('Subject' ,'[no subject]' )
335+ textpart = textwrap .dedent ("""\
336+ This is a message from the datatracker to IETF-Action about an email
337+ delivery failure, when sending email from the datatracker.
334338
335- This is a message from the datatracker to IETF-Action about an email
336- delivery failure, when sending email from the datatracker.
339+ %s
337340
338- %s
339-
340- The original message follows:
341- -------- BEGIN ORIGINAL MESSAGE --------
342- %s
343- --------- END ORIGINAL MESSAGE ---------
344- """ ) % (e .original_msg .get ('Subject' , '[no subject]' ),e .detailed_refusals (),e .original_msg .as_string ())
341+ """ ) % e .detailed_refusals ()
345342 else :
346- msg += textwrap .dedent ("""\
347- Subject: Datatracker error while sending email
348-
349- This is a message from the datatracker to IETF-Action about an email
350- delivery failure, when sending email from the datatracker.
343+ msg ['Subject' ] = 'Datatracker error while sending email'
344+ textpart = textwrap .dedent ("""\
345+ This is a message from the datatracker to IETF-Action about an email
346+ delivery failure, when sending email from the datatracker.
351347
352- The original message was not delivered to anyone.
348+ The original message was not delivered to anyone.
353349
354- SMTP Exception: %s
350+ SMTP Exception: %s
355351
356- Error Message: %s
352+ Error Message: %s
357353
358- """ ) % (extype ,value )
359- if hasattr (e ,'original_msg' ):
360- msg += textwrap .dedent ("""\
361- The original message follows:
362- -------- BEGIN ORIGINAL MESSAGE --------
363- %s
364- --------- END ORIGINAL MESSAGE ---------
365- """ ) % e .original_msg .as_string ()
354+ """ ) % (extype ,value )
355+ if hasattr (e ,'original_msg' ):
356+ textpart += "The original message follows:\n "
357+ msg .attach (MIMEText (textpart ,_charset = 'utf-8' ))
358+ if hasattr (e ,'original_msg' ):
359+ msg .attach (MIMEMessage (e .original_msg ))
366360
367361 send_error_to_secretariat (msg )
368362
369- def send_error_to_secretariat (raw_msg ):
370-
371- (parsed_msg , headers , bcc ) = parse_preformatted (raw_msg )
372- send_msg = encode_message (parsed_msg .get_payload ())
373- cc = None
374- condition_message (parsed_msg ['To' ], parsed_msg ['From' ], parsed_msg ['Subject' ], send_msg , cc , headers )
363+ def send_error_to_secretariat (msg ):
375364
376365 debugging = getattr (settings , "USING_DEBUG_EMAIL_SERVER" , False ) and settings .EMAIL_HOST == 'localhost' and settings .EMAIL_PORT == 2025
377366
378367 try :
379368 if test_mode or debugging or settings .SERVER_MODE == 'production' :
380- send_smtp (send_msg , bcc )
369+ send_smtp (msg , bcc = None )
381370 try :
382371 copy_to = settings .EMAIL_COPY_TO
383372 except AttributeError :
384373 copy_to = "ietf.tracker.archive+%s@gmail.com" % settings .SERVER_MODE
385374 if copy_to and not test_mode and not debugging : # if we're running automated tests, this copy is just annoying
386- if bcc :
387- send_msg ['X-Tracker-Bcc' ]= bcc
388- copy_email (send_msg , copy_to ,originalBcc = bcc )
375+ copy_email (msg , copy_to ,originalBcc = None )
389376 except smtplib .SMTPException :
390377 log ("Exception encountered while sending a ticket to the secretariat" )
391378 (extype ,value ) = sys .exc_info ()[:2 ]
0 commit comments