Hi all,

I would like to seek advice what are the proper dependencies to get the 
debugging information out on my JavaMail.

I am using log4j2 with slf4j.

Here's some background infor:
Tomcat : 8.2.5
Eclipse IDE.
Maven webApp JEE with JSP

Here's my pom for logging dependancies :

<dependencies>
                <dependency>
                        <groupId>javax.servlet.jsp</groupId>
                        <artifactId>javax.servlet.jsp-api</artifactId>
                        <version>2.3.1</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>jsp-api</artifactId>
                        <version>2.0</version>
                </dependency>
                <!-- 
https://mvnrepository.com/artifact/javax.inject/javax.inject -->
                <dependency>
                        <groupId>javax.inject</groupId>
                        <artifactId>javax.inject</artifactId>
                        <version>1</version>
                </dependency>
                <dependency>
                        <groupId>jstl</groupId>
                        <artifactId>jstl</artifactId>
                        <scope>provided</scope>
                        <version>1.2</version>
                </dependency>
                <!-- LOG4J for JDBC -->

                <dependency>
                        <groupId>org.apache.logging.log4j</groupId>
                        <artifactId>log4j-core</artifactId>
                        <version>2.11.2</version>
                </dependency>


                <dependency>
                        <groupId>org.apache.logging.log4j</groupId>
                        <artifactId>log4j-web</artifactId>
                        <version>2.11.2</version>
                </dependency>
                <dependency>
                        <groupId>javax.enterprise</groupId>
                        <artifactId>cdi-api</artifactId>
                        <version>2.0</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>8.0.15</version>
                        <scope>provided</scope>
                </dependency>
                <!-- 
https://mvnrepository.com/artifact/org.postgresql/postgresql -->
                <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>42.2.5</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>javax.servlet-api</artifactId>
                        <version>3.1.0</version>
                        <scope>provided</scope>
                </dependency>
                <!-- 
https://mvnrepository.com/artifact/com.googlecode.log4jdbc/log4jdbc -->
                <dependency>
                        <groupId>com.googlecode.log4jdbc</groupId>
                        <artifactId>log4jdbc</artifactId>
                        <version>1.2</version>
                </dependency>
                <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
                <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>1.7.25</version>
                </dependency>
                <!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail 
-->
                <dependency>
                        <groupId>com.sun.mail</groupId>
                        <artifactId>javax.mail</artifactId>
                        <version>1.6.2</version>
                </dependency>

                <dependency>
                        <groupId>org.apache.logging.log4j</groupId>
                        <artifactId>log4j-slf4j-impl</artifactId>
                        <version>2.11.2</version>
                </dependency>
                <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.11</version>
                        <scope>test</scope>
                </dependency>
        </dependencies>
</project>

And my log4j.xml where I didn't put any type of configuration so I wanted to 
capture all kinds of error and debug infor.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appenders>
        <Console name="console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %c{1} - %msg%n" 
/>
        </Console>
    </appenders>

        <Root level="all">
            <AppenderRef ref="console" />
        </Root>
    
</configuration>


public class sendMail {

        private static final Logger logger = (Logger) 
LogManager.getLogger(sendMail.class);
        private static Connection conn;
        private static PreparedStatement ps = null;

public static void sendEmail(String strEmail) throws MessagingException {
        
                Properties properties = new Properties();
                properties.put("mail.imap.ssl.enable", "true"); // required for 
Gmail
                properties.put("mail.imap.auth.mechanisms", "XOAUTH2");
                properties.setProperty("mail.smtp.host", "smtp.gmail.com");
                properties.put("mail.smtp.port", 587);// for SSL
                properties.put("mail.smtp.auth", true);
                properties.put("mail.smtp.starttls.enable", true);
                properties.put("mail.smtp.socketFactory.class", 
"javax.net.ssl.SSLSocketFactory");
                properties.put("mail.debug", "true");
                //session.setDebug(true);
        
                transport.connect("imap.gmail.com", "xxx", "key");
        
         session = Session.getDefaultInstance(properties, 
                 new javax.mail.Authenticator() {
                     protected PasswordAuthentication 
getPasswordAuthentication(){
                         return new PasswordAuthentication(username, password);
                     } } );


                strEmail = findEmail();
                System.out.println("Email of registered tutor : " + strEmail);
                
                        Message message = new MimeMessage(session);
                        message.setFrom(new InternetAddress("[email protected]"));
                        message.addRecipient(Message.RecipientType.TO, new 
InternetAddress(strEmail));
                        logger.debug(findEmail()); // here I am trying to use 
slf4j or log4j2 to log what's happening here but am not getting infor....
                        message.setSubject("Thank you for registering with us");
                        message.setContent("You have successfully registered", 
"text/html; charset=utf-8");
                        // Send message
                        Transport.send(message);
                        System.out.println("Mail successfully sent");
                }
        }


Hope someone can point out where I am missing.

Thanks & regards,
Karen
_______________________________________________
slf4j-user mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/slf4j-user

Reply via email to