@@ -205,6 +205,19 @@ public Layout Body
205205 /// <docgen category='SMTP Options' order='14' />.
206206 public Layout < bool > EnableSsl { get ; set ; }
207207
208+ /// <summary>
209+ /// Get or set whether the client should use the REQUIRETLS extension if it is available.
210+ /// </summary>
211+ /// <remarks>
212+ /// <para>Gets or sets whether the client should use the REQUIRETLS extension if it is available.</para>
213+ /// <para>The REQUIRETLS extension (as defined in rfc8689) is a way to ensure that every SMTP server
214+ /// that a message passes through on its way to the recipient is required to use a TLS connection in
215+ /// order to transfer the message to the next SMTP server.</para>
216+ /// <note type="note">This feature is only available if connected SMTP server supports capability
217+ /// <see cref="SmtpCapabilities.RequireTLS"/> flag when sending the message.</note>
218+ /// </remarks>
219+ public Layout < bool > RequireTLS { get ; set ; }
220+
208221 /// <summary>
209222 /// Provides a way of specifying the SSL and/or TLS encryption
210223 ///
@@ -354,6 +367,8 @@ private void SendMailMessage(MimeMessage message, LogEventInfo lastEvent)
354367 }
355368
356369 var enableSsl = RenderLogEvent ( EnableSsl , lastEvent ) ;
370+ var requireTLS = RenderLogEvent ( RequireTLS , lastEvent ) ;
371+
357372 var secureSocketOptions = enableSsl ? SecureSocketOptions . SslOnConnect : RenderLogEvent ( SecureSocketOption , lastEvent , DefaultSecureSocketOption ) ;
358373 var smtpPort = RenderLogEvent ( SmtpPort , lastEvent ) ;
359374 InternalLogger . Debug ( "Sending mail to {0} using {1}:{2}" , message . To , renderedHost , smtpPort ) ;
@@ -366,8 +381,13 @@ private void SendMailMessage(MimeMessage message, LogEventInfo lastEvent)
366381 client . ServerCertificateValidationCallback += ( s , cert , chain , sslPolicyErrors ) => true ;
367382 }
368383
384+ if ( requireTLS )
385+ {
386+ client . RequireTLS = true ; // Requires SMTP Server capability SmtpCapabilities.RequireTLS
387+ }
388+
369389 client . Connect ( renderedHost , smtpPort , secureSocketOptions ) ;
370- InternalLogger . Trace ( "{0}: Connecting succesfull" , this ) ;
390+ InternalLogger . Trace ( "{0}: Connecting succesfull with SmtpCapabilities={1} " , this , client . Capabilities ) ;
371391
372392 // Note: since we don't have an OAuth2 token, disable
373393 // the XOAUTH2 authentication mechanism.
0 commit comments