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

📄 sendemailthread.java

📁 CRMS客户关系管理系统(JAVA版),这是一个客户关系管理系统。
💻 JAVA
字号:
	/* CRMS, customer relationship management system	Copyright (C) 2003  Service To Youth Council	This program is free software; you can redistribute it and/or modify	it under the terms of the GNU General Public License as published by	the Free Software Foundation; either version 2 of the License, or	(at your option) any later version.	This program is distributed in the hope that it will be useful,	but WITHOUT ANY WARRANTY; without even the implied warranty of	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	GNU General Public License for more details.	You should have received a copy of the GNU General Public License	along with this program; if not, write to the Free Software	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA	For further information contact the SYC ICT department on GPL@syc.net.au	98 Kermode Street	North Adelaide	South Australia	SA 5006 	+61 (0)8 8367 0755	*//* * SendEmailThread.java * * Created on 20 June 2003, 17:13 */package crms.daemon;import crms.vo.Reminder;import crms.vo.Contact;import crms.vo.Call;import crms.vo.Company;import crms.vo.StaffMember;import crms.util.*;import crms.dao.*;import javax.mail.*;import javax.mail.internet.*;import java.util.*;import java.io.*;import org.apache.log4j.Logger;/** Thread to send an email as per a Reminder request. */public class SendEmailThread {		public static Logger logger = Logger.getLogger(SendEmailThread.class);	LDAPDAO ldapDAO = LDAPDAOFactory.getInstance().getLDAPDAO();	CompanyDAO companyDAO = DAOFactory.getInstance().getCompanyDAO();		private Reminder reminder = null;	private Call call = null;	private Properties mailProperties = null;		/** Creates a new instance of SendEmailThread */	public SendEmailThread(Call call) {		this.call = call;		readProperties();	}		public SendEmailThread(Reminder reminder) {		this.reminder = reminder;		readProperties();	}			/**	 * Loads properties from file called 'mail.properties' to specify	 * mail server settings and various properties of the outgoing reminder	 * emails.	 */	 public void readProperties() {		mailProperties = new Properties();		try {			File f = new File("mail.properties");			mailProperties.load(new FileInputStream(f));			logger.debug("Loaded properties from " + f.toString());		}		catch (Exception ex) {			logger.fatal(ex);		}	}		 	/**	 * Compiles an outgoing text email message based on the supplied 	 * reminder object, and sends it to the server specified in	 * 'mail.properties'	 */	public void run() {				logger.debug("in run()");				Properties props = System.getProperties();		// XXX - could use Session.getTransport() and Transport.connect()		// XXX - assume we're using SMTP				try {			String mailSubject = null;			String mailFrom = mailProperties.getProperty("mail.from","crms@syc.net.au");			String mailHost = mailProperties.getProperty("mail.host","sec.syc.net.au");			props.put("mail.host", mailHost);			// Get a Session object			logger.debug("Getting session object...");			Session session = Session.getDefaultInstance(props, null);			logger.debug("Have session...");			// construct the message			MimeMessage msg = new MimeMessage(session);			msg.setFrom(new InternetAddress(mailFrom));		  	 			StaffMember sm = null;			if (reminder != null) sm = ldapDAO.getUser(reminder.getOwner());			else if (call != null) sm = ldapDAO.getUser(call.getOwner());			logger.debug("Set message details..");						StringBuffer buf = new StringBuffer();			if (reminder != null) {				mailSubject = "CRMS Reminder Notification";				buf.append("A Reminder has been issued from ");				StaffMember smFrom = ldapDAO.getUser(reminder.getCreator());				buf.append(smFrom.getFirstName() + " " + smFrom.getLastName());				buf.append(" through CRMS.\n\n");				buf.append("\n");				buf.append("Date: ");				buf.append(reminder.getReminderDate());				buf.append("\n");				buf.append("Priority: ");				buf.append(reminder.getReminderRate());				buf.append("\n");				/*			int contactid = reminder.getContactID();			if (contactid >= 0) {				ContactDAO dao = DAOFactory.getInstance().getContactDAO();				Contact contact = dao.getContact(contactid);				buf.append("Contact: ");				buf.append(contact.getFirstName());				buf.append(" ");				buf.append(contact.getLastName());				buf.append("\n");		}*/							buf.append("\n");				buf.append("Message:\n");				buf.append(reminder.getReminderMessage());				buf.append("\n\n");				FileAttachmentDAO fileDAO = DAOFactory.getInstance().getFileAttachmentDAO();				List attach = fileDAO.getFileAttachments(EntityType.REMINDER, Integer.toString(reminder.getReminderID()));				if (attach.size() > 0) {					buf.append("There are " + attach.size() + " attachments.");				}			} else if (call != null) {				mailSubject = "CRMS Message Notification";				buf.append("A message has been logged from ");				StaffMember smFrom = ldapDAO.getUser(call.getCreator());				buf.append(smFrom.getFirstName() + " " + smFrom.getLastName());				buf.append(" through CRMS.\n\n");				buf.append("Date: ");				buf.append(call.getDate());				buf.append("\n\n");				buf.append("From: ");				buf.append(call.getFromFirstName());				buf.append(" ");				buf.append(call.getFromLastName());				buf.append("\n");				buf.append("Number: ");				buf.append(call.getNumber());				int companyID = call.getCompanyID();				if (companyID > 0) {					buf.append("\n");					buf.append("Company: ");					buf.append(call.getCompany().getCompanyName());				}					buf.append("\n\n");				buf.append("Message: ");				buf.append(call.getNote());				buf.append("\n\n");				if (call.checkFlag(Call.CALL_FLAG_URGENT)) {					buf.append("* Call is URGENT\n");				}				if (call.checkFlag(Call.CALL_FLAG_PLEASECALL)) {					buf.append("* Please call back\n");				} else if (call.checkFlag(Call.CALL_FLAG_CALLBACK)) {					buf.append("* Caller will call back\n");				}				buf.append("\n");			}							msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(sm.getEmail(), false));			msg.setSubject(mailSubject);			msg.setText(buf.toString());			msg.setHeader("X-Mailer", "CRMS Reminder Daemon");			msg.setSentDate(new Date());			// send the thing off			logger.debug("Beginning delivery.");			Transport.send(msg);			logger.debug("Message sent successfully.");		}		catch (Exception ex) {			ex.printStackTrace();   		}	}	}

⌨️ 快捷键说明

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