Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable java mail trace on console when sending an email

Here is my code for sending email:

    public void sendMail() 
{
    try
    {
        // Propiedades de la conexión
        Properties props = new Properties();
        props.put("mail.transport.protocol", "smtp");
        props.put("mail.smtp.host", SMTP_HOST_NAME);
        props.put("mail.smtp.port", SMTP_PORT);
        props.put("mail.smtp.auth", "true");

        Authenticator auth = new SMTPAuthenticator();
        Session mailSession = Session.getDefaultInstance(props, auth);

        Transport transport = mailSession.getTransport();

        MimeMessage message = new MimeMessage(mailSession);
        Multipart multipart = new MimeMultipart("alternative");

        BodyPart text = new MimeBodyPart();
        text.setContent(mailMessage,"text/html; charset=UTF-8");

        multipart.addBodyPart(text);

        message.setContent(multipart);

        if(friendlyName != null){
            //String send = friendlyName + " <" + sender + ">";
            message.setFrom(new InternetAddress(sender, friendlyName)); 
        }else{
            message.setFrom(new InternetAddress(sender));
        }

        message.setSubject(subject,"UTF-8");
        message.addRecipient(Message.RecipientType.TO,
                new InternetAddress(receiver));

        transport.connect();
        transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
        transport.close();


    }catch (Exception e) {
        // TODO: handle exception
    }

}

When I send an email I get this output on console (or catalina.out):

>>>>>Sending data EHLO xxxxxx<<<<<<

>>>>>Sending data AUTH LOGIN<<<<<<

>>>>>Sending data xxxxxxxxxxxxxxxxxxxx<<<<<<

>>>>>Sending data xxxxxxxxxxxxxx<<<<<<

>>>>>Sending data MAIL FROM: <<<<<<

>>>>>Sending data RCPT TO: <<<<<<

>>>>>Sending data DATA<<<<<<

>>>>>Sending data <<<<<<

>>>>>Sending data .<<<<<<

>>>>>Sending data QUIT<<<<<<

How can I disable this output? My catalina.out is growing too fast. Setdebug(false) method does not solve my problem.

like image 800
user2086740 Avatar asked Feb 19 '13 11:02

user2086740


1 Answers

In spring this worked for me:

    <property name="javaMailProperties">
        <props>
            <prop key="mail.transport.protocol">smtp</prop>
            <prop key="mail.smtp.auth">false</prop>
            <prop key="mail.smtp.starttls.enable">true</prop>
            <prop key="mail.debug">false</prop>
        </props>
    </property>

tested with versions 1.4.7+

like image 164
axetroll Avatar answered Sep 21 '22 10:09

axetroll