I already read this Simple Java Mail wiki tutorial, and I downloaded all the necessary libraries (Log4j, JavaMail API, Activation Environment) although when I try to run my program I get this error:
log4j: WARN No applications were found for the logger (org.codemonkey.vesijama.Mailer). org.codemonkey.vesijama.MailException: general error: log4j exception read response: WARN Please initialize the log4j system correctly.
This is the source code I'm using:
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", " XXXXX@gmail.com "); email.setSubject("hey"); email.addRecipient("hai", " XXXXXXX@yahoo.com ", 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, " XXXXXXXX@gmail.com ", "XXXXXX").sendMail(email); } catch(MailException me) { System.out.println(me); } } }
I also tried using port 587, although I got the same error.
Side question: It also says that you can add attachments. Does anyone have sample code on how I can attach a .xls file.
Edit: I have successfully sent mail (added log4j.xml for each folder), but I still could not use addAttachment . I also updated the source code.
source share