⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsremindermailutil.java.svn-base

📁 一个timesheet程序,用来统计开发人员的度量衡web在线程序.用于软件行业
💻 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");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -