@@ -114,27 +114,25 @@ public MailTarget(string name) : this()
114114 /// Gets or sets sender's email address (e.g. [email protected] ). 115115 /// </summary>
116116 /// <docgen category='Message Options' order='10' />
117- [ RequiredParameter ]
118- public Layout From { get ; set ; }
117+ public Layout From { get ; set ; } = Layout . Empty ;
119118
120119 /// <summary>
121120 /// Gets or sets recipients' email addresses separated by semicolons (e.g. [email protected] ;[email protected] ). 122121 /// </summary>
123122 /// <docgen category='Message Options' order='11' />
124- [ RequiredParameter ]
125- public Layout To { get ; set ; }
123+ public Layout To { get ; set ; } = Layout . Empty ;
126124
127125 /// <summary>
128126 /// Gets or sets CC email addresses separated by semicolons (e.g. [email protected] ;[email protected] ). 129127 /// </summary>
130128 /// <docgen category='Message Options' order='12' />
131- public Layout Cc { get ; set ; }
129+ public Layout ? Cc { get ; set ; }
132130
133131 /// <summary>
134132 /// Gets or sets BCC email addresses separated by semicolons (e.g. [email protected] ;[email protected] ). 135133 /// </summary>
136134 /// <docgen category='Message Options' order='13' />
137- public Layout Bcc { get ; set ; }
135+ public Layout ? Bcc { get ; set ; }
138136
139137 /// <summary>
140138 /// Gets or sets a value indicating whether to add new lines between log entries.
@@ -147,7 +145,6 @@ public MailTarget(string name) : this()
147145 /// Gets or sets the mail subject.
148146 /// </summary>
149147 /// <docgen category='Message Options' order='5' />
150- [ RequiredParameter ]
151148 public Layout Subject { get ; set ; } = "Message from NLog on ${machinename}" ;
152149
153150 /// <summary>
@@ -171,13 +168,13 @@ public Layout Body
171168 /// Gets or sets a value indicating whether to send message as HTML instead of plain text.
172169 /// </summary>
173170 /// <docgen category='Message Options' order='11' />
174- public Layout < bool > Html { get ; set ; }
171+ public Layout < bool > Html { get ; set ; } = false ;
175172
176173 /// <summary>
177174 /// Gets or sets SMTP Server to be used for sending.
178175 /// </summary>
179176 /// <docgen category='SMTP Options' order='10' />
180- public Layout SmtpServer { get ; set ; }
177+ public Layout SmtpServer { get ; set ; } = Layout . Empty ;
181178
182179 /// <summary>
183180 /// Gets or sets SMTP Authentication mode.
@@ -189,21 +186,21 @@ public Layout Body
189186 /// Gets or sets the username used to connect to SMTP server (used when <see cref="SmtpAuthentication"/> is set to "basic").
190187 /// </summary>
191188 /// <docgen category='SMTP Options' order='12' />
192- public Layout SmtpUserName { get ; set ; }
189+ public Layout ? SmtpUserName { get ; set ; }
193190
194191 /// <summary>
195192 /// Gets or sets the password used to authenticate against SMTP server (used when <see cref="SmtpAuthentication"/> is set to "basic").
196193 /// </summary>
197194 /// <docgen category='SMTP Options' order='13' />
198- public Layout SmtpPassword { get ; set ; }
195+ public Layout ? SmtpPassword { get ; set ; }
199196
200197 /// <summary>
201198 /// Gets or sets a value indicating whether SSL (secure sockets layer) should be used when communicating with SMTP server.
202199 ///
203200 /// See also <see cref="SecureSocketOption" />
204201 /// </summary>
205202 /// <docgen category='SMTP Options' order='14' />.
206- public Layout < bool > EnableSsl { get ; set ; }
203+ public Layout < bool > EnableSsl { get ; set ; } = false ;
207204
208205 /// <summary>
209206 /// Get or set whether the client should use the REQUIRETLS extension if it is available.
@@ -216,7 +213,7 @@ public Layout Body
216213 /// <note type="note">This feature is only available if connected SMTP server supports capability
217214 /// <see cref="SmtpCapabilities.RequireTLS"/> flag when sending the message.</note>
218215 /// </remarks>
219- public Layout < bool > RequireTLS { get ; set ; }
216+ public Layout < bool > RequireTLS { get ; set ; } = false ;
220217
221218 /// <summary>
222219 /// Provides a way of specifying the SSL and/or TLS encryption
@@ -237,19 +234,19 @@ public Layout Body
237234 /// Gets or sets a value indicating whether SmtpClient should ignore invalid certificate.
238235 /// </summary>
239236 /// <docgen category='SMTP Options' order='16' />
240- public Layout < bool > SkipCertificateValidation { get ; set ; }
237+ public Layout < bool > SkipCertificateValidation { get ; set ; } = false ;
241238
242239 /// <summary>
243240 /// Gets or sets the priority used for sending mails.
244241 /// </summary>
245242 /// <docgen category='Message Options' order='100' />
246- public Layout Priority { get ; set ; }
243+ public Layout Priority { get ; set ; } = Layout . Empty ;
247244
248245 /// <summary>
249246 /// Gets or sets a value indicating whether NewLine characters in the body should be replaced with <br/> tags.
250247 /// </summary>
251248 /// <remarks>Only happens when <see cref="Html"/> is set to true.</remarks>
252- public Layout < bool > ReplaceNewlineWithBrTagInHtml { get ; set ; }
249+ public Layout < bool > ReplaceNewlineWithBrTagInHtml { get ; set ; } = false ;
253250
254251 /// <summary>
255252 /// Gets or sets a value indicating the SMTP client timeout (in milliseconds)
@@ -261,7 +258,7 @@ public Layout Body
261258 /// Gets or sets the folder where applications save mail messages to be processed by the local SMTP server.
262259 /// </summary>
263260 /// <docgen category='SMTP Options' order='17' />
264- public Layout PickupDirectoryLocation { get ; set ; }
261+ public Layout ? PickupDirectoryLocation { get ; set ; }
265262
266263 /// <summary>
267264 /// Gets the array of email headers that are transmitted with this email message
@@ -483,15 +480,25 @@ internal string ResolvePickupDirectoryLocationFilePath(string pickupDirectoryLoc
483480
484481 private void CheckRequiredParameters ( )
485482 {
483+ if ( From is null || ReferenceEquals ( From , Layout . Empty ) )
484+ {
485+ throw new NLogConfigurationException ( "MailTarget - From address is required" ) ;
486+ }
487+
488+ if ( To is null || ReferenceEquals ( To , Layout . Empty ) )
489+ {
490+ throw new NLogConfigurationException ( "MailTarget - To address is required" ) ;
491+ }
492+
486493 var smtpAuthentication = RenderLogEvent ( SmtpAuthentication , LogEventInfo . CreateNullEvent ( ) ) ;
487494 if ( smtpAuthentication == SmtpAuthenticationMode . Ntlm )
488495 {
489- throw new NLogConfigurationException ( "SmtpAuthentication NTLM not yet supported" ) ;
496+ throw new NLogConfigurationException ( "MailTarget - SmtpAuthentication NTLM not yet supported" ) ;
490497 }
491498
492- if ( PickupDirectoryLocation is null && SmtpServer is null )
499+ if ( ( PickupDirectoryLocation is null || ReferenceEquals ( PickupDirectoryLocation , Layout . Empty ) ) && ( SmtpServer is null || ReferenceEquals ( SmtpServer , Layout . Empty ) ) )
493500 {
494- throw new NLogConfigurationException ( "SmtpServer is required" ) ;
501+ throw new NLogConfigurationException ( "MailTarget - SmtpServer is required" ) ;
495502 }
496503 }
497504
@@ -622,7 +629,7 @@ internal static MessagePriority ParseMessagePriority(string priority)
622629 /// <param name="layout">layout with addresses, ; separated</param>
623630 /// <param name="logEvent">event for rendering the <paramref name="layout" /></param>
624631 /// <returns>added a address?</returns>
625- private bool AddAddresses ( InternetAddressList mailAddressCollection , Layout layout , LogEventInfo logEvent )
632+ private bool AddAddresses ( InternetAddressList mailAddressCollection , Layout ? layout , LogEventInfo logEvent )
626633 {
627634 var added = false ;
628635 var mailAddresses = RenderLogEvent ( layout , logEvent ) ;
0 commit comments