sidhantmourya commented on issue #3704:
URL: 
https://github.com/apache/logging-log4j2/issues/3704#issuecomment-3079210657

   @ppkarwasz  I'm adding custom header support to the SMTP appender similar to 
the HTTP appender, but need guidance on handling the javax.mail vs jakarta.mail 
MimeMessage types - what's the recommended way to implement applyHeaders() to 
work with both implementations? Should I use instanceof checks, create separate 
methods, or is there a better pattern?
   
   my solution is something like this in the Abstract Class curently.
   
   ```
   protected void applyHeaders(final Object message, final StrSubstitutor 
substitutor)
               throws MessagingException, NoSuchMethodException, 
InvocationTargetException, IllegalAccessException {
           Method setHeader = message.getClass().getMethod(
                   "setHeader",
                   String.class,
                   String.class
           );
           for (Property header : headers)
           {
               setHeader.invoke(message, header.getName(), 
substitutor.replace(header.getValue()));
   
           }
       }
   ```
   And then handle the exceptions in the implementation classes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to