?? tsremindermailutil.java.svn-base
字號:
package com.nsi.scheduling;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.nsi.constants.AppConstants;
import com.nsi.control.exceptions.NsiEventException;
/**
* @author Chris Ye, created on Oct 10, 2008
*
* TsReminderMailUtil
*/
public final class TsReminderMailUtil
{
private static Log log = LogFactory.getLog(TsReminderMailUtil.class);
/**
* private constructor of TsReminderMailUtil, prevent instantiation
*/
private TsReminderMailUtil()
{
}
private static class TsReminderMailUtilHolder
{
static final TsReminderMailUtil tsReminderMailUtil = new TsReminderMailUtil();
}
/**
* @return an instance of TsReminderMailUtil
*/
public static TsReminderMailUtil getInstance()
{
return TsReminderMailUtilHolder.tsReminderMailUtil;
}
public void sendTsReminderMaills() throws NsiEventException
{
List<RsEmailInfo> emailist = RsMailInfoUtil.getInstance().getEmaillist();
sendTsReminderMaill(emailist);
}
public void sendTsReminderMaill(List<RsEmailInfo> emailist) throws NsiEventException
{
if(!emailist.isEmpty())
{
log.debug("sendTsReminderMaill() -- emailist is not empty, start sending mail");
int size = emailist.size();
for (int i = 0; i < size; i++)
{
RsEmailInfo info = emailist.get(i);
try
{
Properties properties = System.getProperties();
properties.put(AppConstants.MAILPROVIDER, AppConstants.SMTPHOST);
Session session = Session.getInstance(properties, null);
MimeMessage mimemessage = new MimeMessage(session);
InternetAddress internetaddress = new InternetAddress(AppConstants.FROM_ADMIN);
mimemessage.setFrom(internetaddress);
mimemessage.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(info.getEmail()));
mimemessage.setSubject("Timesheet Entry Reminder");
mimemessage.setSentDate(new Date());
String msgbody = info.getResourcename() + " : \n\n";
msgbody = msgbody + "Just a reminder! Please complete and finalize your current week's timesheet by next Monday before 11:59AM. \n\n";
msgbody = msgbody + "If next Monday is Stat. Holiday, please complete and finalize your timesheet before you leave the office today.\n\n";
msgbody = msgbody + "RMS allows you to finalize your future timesheet up to 4 weeks. In case you take a long vacation, please complete your timesheet before you take your leave.\n\n";
msgbody = msgbody + "Thank you for your co-operation!\n\n";
msgbody = msgbody + "\nRMS Admin\n\n";
mimemessage.setText(msgbody);
Transport.send(mimemessage);
}
catch(AddressException addressexception)
{
log.error("sendTsReminderMaills() -- caught addressexception : ", addressexception );
throw new NsiEventException( "sendTsReminderMaills() -- caught addressexception : ", addressexception);
}
catch(SendFailedException sendfailedexception)
{
log.error("sendTsReminderMaills() -- caught sendfailedexception : ", sendfailedexception );
throw new NsiEventException( "sendTsReminderMaills() -- caught sendfailedexception : ", sendfailedexception);
}
catch(MessagingException messagingexception)
{
log.error("sendTsReminderMaills() -- caught messagingexception : ", messagingexception );
throw new NsiEventException( "sendTsReminderMaills() -- caught messagingexception : ", messagingexception);
}
catch(Exception ex)
{
log.error("sendTsReminderMaills() -- caught exception : ", ex );
throw new NsiEventException( "sendTsReminderMaills() -- caught exception : ", ex);
}
}
log.debug("sendTsReminderMaill() -- emailist is not empty, completed sending mail");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -