01: /**
02: * Copyright (c) 2004-2005 jManage.org
03: *
04: * This is a free software; you can redistribute it and/or
05: * modify it under the terms of the license at
06: * http://www.jmanage.org.
07: *
08: * Unless required by applicable law or agreed to in writing, software
09: * distributed under the License is distributed on an "AS IS" BASIS,
10: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: * See the License for the specific language governing permissions and
12: * limitations under the License.
13: */package org.jmanage.core.util;
14:
15: import javax.mail.MessagingException;
16: import javax.mail.Session;
17: import javax.mail.Message;
18: import javax.mail.Transport;
19: import javax.mail.internet.MimeMessage;
20: import java.util.Properties;
21: import java.util.logging.Logger;
22:
23: /**
24: * @author Bhavana
25: * @author Rakesh Kalra
26: */
27: public class EmailUtils {
28:
29: private static final Logger logger = Loggers
30: .getLogger(EmailUtils.class);
31:
32: public static void sendEmail(String to, String subject,
33: String content) throws MessagingException {
34:
35: logger.fine("Sending email to: " + to);
36:
37: Properties properties = new Properties();
38: properties.put("mail.user", JManageProperties
39: .getAlertEmailFromName());
40: properties.put("mail.host", JManageProperties.getEmailHost());
41: properties.put("mail.from", JManageProperties
42: .getAlertEmailFrom());
43: properties.put("mail.transport.protocol", "smtp");
44: Session session = Session.getInstance(properties);
45: MimeMessage message = new MimeMessage(session);
46: message.addRecipients(Message.RecipientType.TO, to);
47: message.setSubject(subject);
48: message.setText(content);
49: Transport.send(message);
50: }
51: }
|