KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > util > EmailUtils


1 /**
2 * Copyright (c) 2004-2005 jManage.org
3 *
4 * This is a free software; you can redistribute it and/or
5 * modify it under the terms of the license at
6 * http://www.jmanage.org.
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * 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 */

14 package org.jmanage.core.util;
15
16 import javax.mail.MessagingException JavaDoc;
17 import javax.mail.Session JavaDoc;
18 import javax.mail.Message JavaDoc;
19 import javax.mail.Transport JavaDoc;
20 import javax.mail.internet.MimeMessage JavaDoc;
21 import java.util.Properties JavaDoc;
22 import java.util.logging.Logger JavaDoc;
23
24 /**
25  * @author Bhavana
26  * @author Rakesh Kalra
27  */

28 public class EmailUtils {
29
30     private static final Logger JavaDoc logger = Loggers.getLogger(EmailUtils.class);
31
32     public static void sendEmail(String JavaDoc to, String JavaDoc subject, String JavaDoc content)
33             throws MessagingException JavaDoc{
34
35         logger.fine("Sending email to: " + to);
36
37         Properties JavaDoc properties = new Properties JavaDoc();
38         properties.put("mail.user", JManageProperties.getAlertEmailFromName());
39         properties.put("mail.host", JManageProperties.getEmailHost());
40         properties.put("mail.from", JManageProperties.getAlertEmailFrom());
41         properties.put("mail.transport.protocol", "smtp");
42         Session JavaDoc session = Session.getInstance(properties);
43         MimeMessage JavaDoc message = new MimeMessage JavaDoc(session);
44         message.addRecipients(Message.RecipientType.TO, to);
45         message.setSubject(subject);
46         message.setText(content);
47         Transport.send(message);
48     }
49 }
50
Popular Tags