@@ -91,7 +91,7 @@ public class MailTarget : TargetWithLayoutHeaderAndFooter
9191 /// Initializes a new instance of the <see cref="MailTarget" /> class.
9292 /// </summary>
9393 /// <remarks>
94- /// The default value of the layout is: <code>${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true }</code>
94+ /// The default value of the Body-Layout is: <code>${message}${newline }</code>
9595 /// </remarks>
9696 public MailTarget ( )
9797 {
@@ -102,7 +102,7 @@ public MailTarget()
102102 /// Initializes a new instance of the <see cref="MailTarget" /> class.
103103 /// </summary>
104104 /// <remarks>
105- /// The default value of the layout is: <code>${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true }</code>
105+ /// The default value of the Body-Layout is: <code>${message}${newline }</code>
106106 /// </remarks>
107107 /// <param name="name">Name of the target.</param>
108108 public MailTarget ( string name ) : this ( )
@@ -309,7 +309,7 @@ private void ProcessSingleMailMessage(IEnumerable<AsyncLogEventInfo> events)
309309 {
310310 client . Timeout = RenderLogEvent ( Timeout , lastEvent ) ;
311311
312- var renderedHost = SmtpServer . Render ( lastEvent ) ;
312+ var renderedHost = RenderLogEvent ( SmtpServer , lastEvent ) ;
313313 if ( string . IsNullOrEmpty ( renderedHost ) )
314314 {
315315 throw new NLogRuntimeException ( string . Format ( RequiredPropertyIsEmptyFormat , nameof ( SmtpServer ) ) ) ;
@@ -341,8 +341,8 @@ private void ProcessSingleMailMessage(IEnumerable<AsyncLogEventInfo> events)
341341 var smtpAuthentication = RenderLogEvent ( SmtpAuthentication , LogEventInfo . CreateNullEvent ( ) ) ;
342342 if ( smtpAuthentication == SmtpAuthenticationMode . Basic )
343343 {
344- var userName = SmtpUserName ? . Render ( lastEvent ) ;
345- var password = SmtpPassword ? . Render ( lastEvent ) ;
344+ var userName = RenderLogEvent ( SmtpUserName , lastEvent ) ;
345+ var password = RenderLogEvent ( SmtpPassword , lastEvent ) ;
346346
347347 InternalLogger . Debug ( "Authenticate with username '{0}'" , userName ) ;
348348 client . Authenticate ( userName , password ) ;
@@ -465,9 +465,9 @@ private MimeMessage CreateMailMessage(LogEventInfo lastEvent, string body)
465465
466466 msg . Subject = ( RenderLogEvent ( Subject , lastEvent ) ?? string . Empty ) . Trim ( ) ;
467467
468- if ( Priority != null )
468+ var renderedPriority = RenderLogEvent ( Priority , lastEvent ) ;
469+ if ( ! string . IsNullOrEmpty ( renderedPriority ) )
469470 {
470- var renderedPriority = Priority . Render ( lastEvent ) ;
471471 msg . Priority = ParseMessagePriority ( renderedPriority ) ;
472472 }
473473
@@ -477,6 +477,10 @@ private MimeMessage CreateMailMessage(LogEventInfo lastEvent, string body)
477477 if ( html && replaceNewlineWithBrTagInHtml )
478478 {
479479 newBody = newBody ? . Replace ( Environment . NewLine , "<br/>" ) ;
480+ if ( newBody ? . IndexOf ( '\n ' ) >= 0 )
481+ {
482+ newBody = newBody ? . Replace ( "\n " , "<br/>" ) ;
483+ }
480484 }
481485
482486 var encoding = RenderLogEvent ( Encoding , lastEvent , DefaultEncoding ) ;
@@ -486,16 +490,19 @@ private MimeMessage CreateMailMessage(LogEventInfo lastEvent, string body)
486490 ContentType = { Charset = encoding ? . WebName }
487491 } ;
488492
489-
490493 if ( MailHeaders ? . Count > 0 )
491494 {
492495 for ( int i = 0 ; i < MailHeaders . Count ; i ++ )
493496 {
497+ var headerName = MailHeaders [ i ] . Name ;
498+ if ( string . IsNullOrEmpty ( headerName ) )
499+ continue ;
500+
494501 string headerValue = RenderLogEvent ( MailHeaders [ i ] . Layout , lastEvent ) ;
495502 if ( headerValue is null )
496503 continue ;
497504
498- msg . Headers . Add ( MailHeaders [ i ] . Name , headerValue ) ;
505+ msg . Headers . Add ( headerName , headerValue ) ;
499506 }
500507 }
501508
0 commit comments