Reputation: 5952
I want to send log files to a given email address. Here is how I tried it.But it didn't work.
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.net.SMTPAppender;
public class LogSender {
static Logger logger = Logger.getLogger(test.class);
SMTPAppender appender = new SMTPAppender();
public test() {
try {
appender.setTo("[email protected]");
appender.setFrom("[email protected]");
appender.setSMTPHost("smtp.gmail.com");
appender.setSMTPUsername("[email protected]");
appender.setSMTPPassword("mypassword");
appender.setLocationInfo(true);
appender.setSubject("Test Mail From Log4J");
appender.setLayout(new PatternLayout());
appender.activateOptions();
logger.addAppender(appender);
logger.error("This is an error");
}
catch(Exception e) {
e.printStackTrace();
logger.error("Thrown exception",e);
}
}
public static void main(String args[]) {
LogSender l = new LogSender;
}
}
There is an exceptions saying
log4j:ERROR Error occured while sending e-mail notification.
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. ee6sm12133321igc.6
Any one tell my where the problem is and how I can solve this or give me any working sample code please.
Upvotes: 1
Views: 1679
Reputation: 6499
Looks like you need to use secure connection: http://railsforum.com/viewtopic.php?id=20777. Some links: http://www.tgerm.com/2010/05/log4j-smtpappender-gmail-custom.html, http://codelol.com/2009/09/log4j-smtpappender-and-authentication/
Upvotes: 1