KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/mail/CmsMultiPartMail.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.MultiPartEmail;
42
43 /**
44  * This class is used to send multi-part internet email like
45  * messages with attachments.<p>
46  *
47  * It uses the Apache Commons Email API and extends the provided classes
48  * to conveniently generate emails using the OpenCms configuration.<p>
49  *
50  * @author Andreas Zahner
51  *
52  * @version $Revision: 1.8 $
53  *
54  * @since 6.0.0
55  */

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

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