KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > mail > CmsHtmlMail


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/mail/CmsHtmlMail.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.8 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.mail;
33
34 import org.opencms.main.CmsLog;
35 import org.opencms.main.OpenCms;
36 import org.opencms.util.CmsStringUtil;
37
38 import javax.mail.MessagingException JavaDoc;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.mail.HtmlEmail;
42
43 /**
44  * This class is used to send an HTML formatted email with optional attachments.<p>
45  *
46  * A text message can also be set for HTML unaware email clients,
47  * such as text-based email clients.<p>
48  *
49  * It uses the Apache Commons Email API and extends the provided classes
50  * to conveniently generate emails using the OpenCms configuration.<p>
51  *
52  * @author Andreas Zahner
53  *
54  * @version $Revision: 1.8 $
55  *
56  * @since 6.0.0
57  */

58 public class CmsHtmlMail extends HtmlEmail {
59
60     /** The log object for this class. */
61     private static final Log LOG = CmsLog.getLog(CmsHtmlMail.class);
62
63     /**
64      * Default constructor of a CmsHtmlMail.<p>
65      *
66      * The mail host name and the mail from address are set to the OpenCms
67      * default values of the configuration.<p>
68      *
69      */

70     public CmsHtmlMail() {
71
72         // call super constructor
73
super();
74         // set the host to the default mail host
75
CmsMailHost host = OpenCms.getSystemInfo().getMailSettings().getDefaultMailHost();
76         setHostName(host.getHostname());
77
78         // check if username and password are provided
79
String JavaDoc userName = host.getUsername();
80         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(userName)) {
81             // authentication needed, set user name and password
82
setAuthentication(userName, host.getPassword());
83         }
84         try {
85             // set default mail from address
86
setFrom(OpenCms.getSystemInfo().getMailSettings().getMailFromDefault());
87         } catch (MessagingException JavaDoc e) {
88             // default email address is not valid, log error
89
LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_SENDER_ADDRESS_0), e);
90         }
91     }
92
93 }
94
Popular Tags