ベロシティを使用して、送信する電子メール用の HTML テンプレート ベースのコンテンツを生成し、Java Mail APIと Spring のMimeMessageHelperを使用して電子メールを送信しています。私が直面している問題は、レンダリング中に HTML テンプレートがスローされcatalina.out
、ファイルのサイズが大きくなり、望ましくないことです。
ログが生成される別のアプリケーション ログ ファイルがあります。このレンダリングをアプリケーション ログ ファイルにリダイレクトする方法はありますか? または、これが投げられるのを止めることができるかもしれませんcatalina.out
。
以下は、電子メールの送信中に書き込まれる詳細です
Loading javamail.default.providers from jar:file:/D:/workspace/EmailService/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/email-service/WEB-INF/lib/mail-1.4.jar!/META-INF/javamail.default.providers
DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=imaps, className=com.sun.mail.imap.IMAPSSLStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtps, className=com.sun.mail.smtp.SMTPSSLTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3s, className=com.sun.mail.pop3.POP3SSLStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type@2025b64d; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.nagarro.com", port 587, isSSL false
220 fuseout2c MailAnyone extSMTP Tue, 23 Jul 2013 02:37:58 -0700
DEBUG SMTP: connected to host "smtp.nagarro.com", port: 587
EHLO Vaibhav202001
250-fuseout2c Hello Vaibhav202001 [14.141.12.161]
250-SIZE 52428800
250-PIPELINING
250-AUTH LOGIN
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
STARTTLS
220 TLS go ahead
EHLO Vaibhav202001
250-fuseout2c Hello Vaibhav202001 [14.141.12.161]
250-SIZE 52428800
250-PIPELINING
250-AUTH LOGIN
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
anNhZy5zdXBwb3J0QG5hZ2Fycm8uY29t
334 UGFzc3dvcmQ6
SnNhZ0AxMjM0
235 Authentication succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<jsagteam@nagarro.com>
250 OK
RCPT TO:<vaibhav.shukla@nagarro.com>
250 Accepted
DEBUG SMTP: Verified Addresses
DEBUG SMTP: vaibhav.shukla@nagarro.com
DATA
354 Enter message, ending with "." on a line by itself
Date: Fri, 26 Jul 2013 12:00:48 +0530 (IST)
From: JSAG Team <jsagteam@nagarro.com>
To: vaibhav.shukla@nagarro.com
Message-ID: <1817391686.01374820248531.JavaMail.vaibhav2020@Vaibhav202001>
Subject: JSAG Home page - subscribers list
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_999692932.1374820244866"
------=_Part_0_999692932.1374820244866
Content-Type: multipart/related;
boundary="----=_Part_1_1241615899.1374820244889"
------=_Part_1_1241615899.1374820244889
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
//My Email Template goes here
------=_Part_1_1241615899.1374820244889--
------=_Part_0_999692932.1374820244866--
250 OK id=1V1Z2g-0002Rh-HO
QUIT
221 fuseout2c closing connection
そして、ここにロギング構成があります
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/email-service.log
log4j.appender.file.MaxFileSize=1000KB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-4p %m%n
log4j.appender.DatePattern='.'yyyy-MM-dd
# Root logger option
log4j.rootLogger=WARN, file
log4j.logger.com.nagarro=WARN
また、電子メールを送信するためのコード
JavaMailSender mailSender; // injected through Spring DI
/**
* The mail message.
*/
SimpleMailMessage mailMessage; // Spring DI
@Override
public void sendEMail(final EmailServiceRequest request, byte[] data) {
MimeMessage message = mailSender.createMimeMessage();
OutputStream outStream = null;
try {
MimeMessageHelper helper = new MimeMessageHelper(message, true);
// set attributes
if (null != request.getRecipientEmailId()) {
helper.setTo(request.getRecipientEmailId());
}
helper.setFrom(request.getSenderEmailId());
helper.setSubject(request.getSubject());
helper.setText(request.getContent(), true);
// check for recipient list
if (null != request.getRecipients() && !request.getRecipients().isEmpty()) {
InternetAddress[] recipients = new InternetAddress[request.getRecipients().size()];
for (int index = 0; index < request.getRecipients().size(); index++) {
recipients[index] = new InternetAddress(request.getRecipients().get(index));
}
helper.setTo(recipients);
}
// data handler
if (null != data) {
try {
File file = File.createTempFile(request.getAttachmentName(), "");
outStream = new FileOutputStream(file);
outStream.write(data);
helper.addAttachment(request.getAttachmentName(), file);
} catch (IOException e) {
logger.error(e.getMessage(), e);
} finally {
try {
outStream.flush();
outStream.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
if (!StringUtil.isNullOrEmpty(request.getEmailIdCC())) {
helper.addCc(request.getEmailIdCC());
}
if (!StringUtil.isNullOrEmpty(request.getEmailIdBCC())) {
helper.addBcc(request.getEmailIdBCC());
}
mailSender.send(message);
} catch (MessagingException e) {
logger.error(e.getLocalizedMessage(), e);
}
}