@@ -205,6 +205,19 @@ public Layout Body
205
205
/// <docgen category='SMTP Options' order='14' />.
206
206
public Layout < bool > EnableSsl { get ; set ; }
207
207
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
+
208
221
/// <summary>
209
222
/// Provides a way of specifying the SSL and/or TLS encryption
210
223
///
@@ -354,6 +367,8 @@ private void SendMailMessage(MimeMessage message, LogEventInfo lastEvent)
354
367
}
355
368
356
369
var enableSsl = RenderLogEvent ( EnableSsl , lastEvent ) ;
370
+ var requireTLS = RenderLogEvent ( RequireTLS , lastEvent ) ;
371
+
357
372
var secureSocketOptions = enableSsl ? SecureSocketOptions . SslOnConnect : RenderLogEvent ( SecureSocketOption , lastEvent , DefaultSecureSocketOption ) ;
358
373
var smtpPort = RenderLogEvent ( SmtpPort , lastEvent ) ;
359
374
InternalLogger . Debug ( "Sending mail to {0} using {1}:{2}" , message . To , renderedHost , smtpPort ) ;
@@ -366,8 +381,13 @@ private void SendMailMessage(MimeMessage message, LogEventInfo lastEvent)
366
381
client . ServerCertificateValidationCallback += ( s , cert , chain , sslPolicyErrors ) => true ;
367
382
}
368
383
384
+ if ( requireTLS )
385
+ {
386
+ client . RequireTLS = true ; // Requires SMTP Server capability SmtpCapabilities.RequireTLS
387
+ }
388
+
369
389
client . Connect ( renderedHost , smtpPort , secureSocketOptions ) ;
370
- InternalLogger . Trace ( "{0}: Connecting succesfull" , this ) ;
390
+ InternalLogger . Trace ( "{0}: Connecting succesfull with SmtpCapabilities={1} " , this , client . Capabilities ) ;
371
391
372
392
// Note: since we don't have an OAuth2 token, disable
373
393
// the XOAUTH2 authentication mechanism.
0 commit comments