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("receiver@gmail.com");
appender.setFrom("sender@gmail.com");
appender.setSMTPHost("smtp.gmail.com");
appender.setSMTPUsername("sender@gmail.com");
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.
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/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.