tags:

views:

48

answers:

1

Hi, i already read this tutorial from here and i have download all required libraries (Log4j, JavaMail API ,Activation framework) . But when i trying running this program i got this error

log4j:WARN No appenders could be found for logger (org.codemonkey.vesijama.Mailer). org.codemonkey.vesijama.MailException: Generic error: Exception reading response log4j:WARN Please initialize the log4j system properly.

this is the source code i use

import javax.mail.Message.RecipientType;
import org.codemonkey.vesijama.Email;
import org.codemonkey.vesijama.MailException;
import org.codemonkey.vesijama.Mailer;
import org.apache.log4j.*;
public class testSend {
final Email email = new Email();
static Logger log = Logger.getLogger(mailmailan.class);
public testSend{
 try{
    BasicConfigurator.configure();
    email.setFromAddress("test", "[email protected]");
    email.setSubject("hey");
    email.addRecipient("hai", "[email protected]", RecipientType.TO);
    email.setText("We should meet up!");
    email.setTextHTML("<b>We should meet up!</b>");
    email.addAttachment("output.xls", odfDatasource);
    new Mailer("smtp.gmail.com", 465, "[email protected]", "XXXXXX").sendMail(email);
    }
        catch(MailException me)
        {
            System.out.println(me);
        }
}
}

i have also trying using port 587. but i got same error >.<

btw , it say can add attachments what should i write if i want to attach .xls ( microsoft excel 2003) ?

Thx B4.

Edit : i have success send mail (Add log4j.xml in every folder @.@), but i still failed to addAttachment. And i just change my source code.

+1  A: 

The first error you are getting is related to not being able to find a log4j.xml file in the classpath to configure log4j logging.

Solving that problem should give you more logging to help you solve any other remaining problems.

You'll need to create a log4j configuration file to see the output.

Googling for "simple log4j.xml" found this example quickly:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"&gt;
  <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.SimpleLayout"/>
  </appender>
  <category name="com.something.something.you.want.to.see.debug">
    <priority value="debug"/>
  </category><root><priority value="info"/>
    <appender-ref ref="ConsoleAppender"/>
  </root>
</log4j:configuration>

This logs info messages for everything, and debug for stuff specified in the named category (I called "com.something.something.you.want.to.see.debug") Typically this name is the same as your package structure.

Search for log4j tutorials to learn more options for log4j configuration.

Alex B
thx for log4j.xml , now my problem just need learn how to make attachment
Huuhaacece