Source code: com/opencms/defaults/CmsMail.java
1 /*
2 * File : $Source: /usr/local/cvs/opencms/src/com/opencms/defaults/CmsMail.java,v $
3 * Date : $Date: 2003/02/15 11:14:57 $
4 * Version: $Revision: 1.14 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
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 OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */
28
29 package com.opencms.defaults;
30
31 import com.opencms.boot.I_CmsLogChannels;
32 import com.opencms.file.*;
33 import com.opencms.core.*;
34 import com.opencms.util.*;
35 import javax.mail.*;
36 import javax.activation.*;
37 import javax.mail.internet.*;
38 import java.util.*;
39
40 /**
41 * This class is used to send a mail using the JavaMail package.
42 * Sun's <code>mail.jar</code> and <code>activation.jar</code> are required,
43 * if this class should be used in any OpenCms class.
44 * <P>
45 * Sender and recipients addresses may be given as <code>String</code>
46 * or as <code>CmsUser</code> objects.
47 * Different constructors for setting additional CC and BCC addresses are provided.
48 * <P>
49 * Attachments can be added using the <code>addAttachment()</code> method.
50 * If the current HTTP request is a <code>multipart/form-data</code> request
51 * and contains uploaded files, all these files will be sent as attachments, too.
52 * <P>
53 * For performance reasons, this classes uses threads for sending mails.
54 * Mail threads can be initialized and started by :
55 * <ul>
56 * <li>creating a new CmsMail object with the appropriate constructor</li>
57 * <li>eventually adding one ore more attachments to this objects</li>
58 * <li>calling the <code>start()</code> method on this object.
59 * </ul>
60 * <P>
61 * Example:<br><code>
62 * String from = "waruschan.babachan@framfab.de";<br>
63 * String[] to = {"alexander.lucas@framfab.de"};<br>
64 * String subject = "Testmail";<br>
65 * String content = "Hello World!";<br>
66 * <br>
67 * CmsMail mail=new CmsMail(cms, from, to, subject, content, "text/plain");<br>
68 * mail.start();<br>
69 * </code>
70 *
71 * @author Waruschan Babachan <waruschan.babachan@framfab.de>
72 * @author mla
73 * @author Alexander Lucas <alexander.lucas@framfab.de>
74 *
75 * @version $Name: $ $Revision: 1.14 $ $Date: 2003/02/15 11:14:57 $
76 * @since OpenCms 4.1.37. Previously, this class was part of the <code>com.opencms.workplace</code> package.
77 */
78 public class CmsMail extends Thread implements I_CmsLogChannels {
79
80 // constants
81 private String c_FROM = "";
82 private String[] c_TO = null;
83 private String[] c_BCC = null;
84 private String[] c_CC = null;
85 private String c_MAILSERVER = "";
86 private String c_ALTERNATIVE_MAILSERVER = "";
87 private String c_SUBJECT = "";
88 private String c_CONTENT = "";
89 private String c_TYPE = "";
90 private CmsObject c_CMS = null;
91 private Vector attachContent = new Vector();
92 private Vector attachType = new Vector();
93
94 /**
95 * The constuctors without CmsObject
96 */
97 public CmsMail(String from, String[] to, String subject, String content, String type) throws CmsException {
98 this(null, from, to, subject, content, type);
99 }
100 public CmsMail(CmsUser from, CmsUser[] to, String subject, String content, String type) throws CmsException {
101 this(null, from, to, subject, content, type);
102 }
103 public CmsMail(CmsUser from, CmsGroup to, String subject, String content, String type) throws CmsException {
104 this(null, from, to, subject, content, type);
105 }
106 public CmsMail(String from, String[] to, String[] cc, String[] bcc, String subject, String content, String type) throws com.opencms.core.CmsException {
107 this(null, from, to, cc, bcc, subject, content, type);
108 }
109 public CmsMail(String from, String[] to, String[] bcc, String subject, String content, String type) throws CmsException {
110 this(null, from, to, bcc, subject, content, type);
111 }
112
113 /**
114 * Create a new email object with a <code>CmsUser</code> as sender and an array of
115 * <code>CmsUser</code>'s as recipient(s). Email addresses will be taken from
116 * the CmsUser properties.
117 *
118 * @param cms Cms object
119 * @param from User object that contains the address of sender.
120 * @param to User object that contains the address of recipient.
121 * @param subject Subject of email.
122 * @param content Content of email.
123 * @param type ContentType of email.
124 */
125 public CmsMail(CmsObject cms, CmsUser from, CmsUser[] to, String subject, String content, String type) throws CmsException {
126
127 // Get Registry
128 I_CmsRegistry reg = com.opencms.core.OpenCms.getRegistry();
129
130 // check sender email address
131 String fromAddress = from.getEmail();
132 if(fromAddress == null || fromAddress.equals("")) {
133 fromAddress = reg.getSystemValue("defaultmailsender");
134 }
135 if(fromAddress == null || fromAddress.equals("")) {
136 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown sender email address.", CmsException.C_BAD_NAME);
137 }
138 if(fromAddress.indexOf("@") == -1 || fromAddress.indexOf(".") == -1) {
139 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown sender email address: " + fromAddress, CmsException.C_BAD_NAME);
140 }
141
142 // check recipient email address
143 Vector v = new Vector(to.length);
144 for(int i = 0;i < to.length;i++) {
145 if(to[i].getEmail() == null) {
146 continue;
147 }
148 if(to[i].getEmail().equals("")) {
149 continue;
150 }
151 if(to[i].getEmail().indexOf("@") == -1 || to[i].getEmail().indexOf(".") == -1) {
152 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email, Invalid recipient email address: " + to[i].getEmail(), CmsException.C_BAD_NAME);
153 }
154 v.addElement(to[i].getEmail());
155 }
156 String users[] = new String[v.size()];
157 for(int i = 0;i < v.size();i++) {
158 users[i] = (String)v.elementAt(i);
159 }
160 if(users.length == 0) {
161 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown recipient email address.", CmsException.C_BAD_NAME);
162 }
163 c_TO = users;
164 c_FROM = fromAddress;
165 c_SUBJECT = (subject == null ? "" : subject);
166 c_CONTENT = (content == null ? "" : content);
167 c_MAILSERVER = reg.getSystemValue("smtpserver");
168 c_ALTERNATIVE_MAILSERVER = reg.getSystemValue("smtpserver2");
169 c_TYPE = type;
170 c_CMS = cms;
171 }
172
173 /**
174 * Create a new email object with a <code>CmsUser</code> as sender and a
175 * <code>CmsGroup</code> as recipient(s). The sender's address will be taken from
176 * the CmsUser properties, the recipient's addresses from all CmsUsers
177 * belonging to the given group.
178 *
179 * @param cms Cms object.
180 * @param from User object that contains the address of sender.
181 * @param to Group object that contains the address of recipient.
182 * @param subject Subject of email.
183 * @param content Content of email.
184 * @param type ContentType of email.
185 */
186 public CmsMail(CmsObject cms, CmsUser from, CmsGroup to, String subject, String content, String type) throws CmsException {
187
188 // Get Registry
189 I_CmsRegistry reg = com.opencms.core.OpenCms.getRegistry();
190
191 // check sender email address
192 String fromAddress = from.getEmail();
193 if(fromAddress == null || fromAddress.equals("")) {
194 fromAddress = reg.getSystemValue("defaultmailsender");
195 }
196 if(fromAddress == null || fromAddress.equals("")) {
197 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown sender email address.", CmsException.C_BAD_NAME);
198 }
199 if(fromAddress.indexOf("@") == -1 || fromAddress.indexOf(".") == -1) {
200 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown sender email address: " + fromAddress, CmsException.C_BAD_NAME);
201 }
202
203 // check recipient email address
204 Vector vu = cms.getUsersOfGroup(to.getName());
205 Vector v = new Vector(vu.size());
206 for(int i = 0;i < vu.size();i++) {
207 String address = ((CmsUser)vu.elementAt(i)).getEmail();
208 if(address == null) {
209 continue;
210 }
211 if(address.equals("")) {
212 continue;
213 }
214 if(address.indexOf("@") == -1 || address.indexOf(".") == -1) {
215 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email, Invalid recipient email address: " + address, CmsException.C_BAD_NAME);
216 }
217 v.addElement(address);
218 }
219 String users[] = new String[v.size()];
220 for(int i = 0;i < v.size();i++) {
221 users[i] = (String)v.elementAt(i);
222 }
223 if(users.length == 0) {
224 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown recipient email address.", CmsException.C_BAD_NAME);
225 }
226 c_TO = users;
227 c_FROM = fromAddress;
228 c_SUBJECT = (subject == null ? "" : subject);
229 c_CONTENT = (content == null ? "" : content);
230 c_MAILSERVER = reg.getSystemValue("smtpserver");
231 c_ALTERNATIVE_MAILSERVER = reg.getSystemValue("smtpserver2");
232 c_TYPE = type;
233 c_CMS = cms;
234 }
235
236 /**
237 * Create a new email object with given FROM, TO, CC and BCC addresses.
238 *
239 * @see #CmsMail(CmsObject,String, String[], String[], String, String, String)
240 *
241 * @param cms Cms object.
242 * @param from Address of sender.
243 * @param to Address of recipient.
244 * @param cc Address of copy recipient.
245 * @param bcc Address of blank copy recipient.
246 * @param subject Subject of email.
247 * @param content Content of email.
248 * @param type ContentType of email.
249 */
250 public CmsMail(CmsObject cms, String from, String[] to, String[] cc, String[] bcc, String subject, String content, String type) throws com.opencms.core.CmsException {
251 this(cms, from, to, bcc, subject, content, type);
252 Vector v = new Vector();
253 for(int i = 0;i < cc.length;i++) {
254 if(cc[i] == null) {
255 continue;
256 }
257 if(cc[i].equals("")) {
258 continue;
259 }
260 if(cc[i].indexOf("@") == -1 || cc[i].indexOf(".") == -1) {
261 continue;
262 }
263 v.addElement(cc[i]);
264 }
265 String users[] = new String[v.size()];
266 for(int i = 0;i < v.size();i++) {
267 users[i] = (String)v.elementAt(i);
268 }
269 if(users.length == 0) {
270 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown recipient email address.", CmsException.C_BAD_NAME);
271 }
272 c_CC = users;
273 }
274
275 /**
276 * Create a new email object with given FROM, TO and BCC addresses.
277 *
278 * @see #CmsMail(CmsObject,String, String[], String, String, String)
279 *
280 * @param cms Cms object.
281 * @param from Address of sender.
282 * @param to Address of recipient.
283 * @param bcc Address of blank copy recipient.
284 * @param subject Subject of email.
285 * @param content Content of email.
286 * @param type ContentType of email.
287 */
288 public CmsMail(CmsObject cms, String from, String[] to, String[] bcc, String subject, String content, String type) throws CmsException {
289 this(cms, from, to, subject, content, type);
290 Vector v = new Vector();
291 for(int i = 0;i < bcc.length;i++) {
292 if(bcc[i] == null) {
293 continue;
294 }
295 if(bcc[i].equals("")) {
296 continue;
297 }
298 if(bcc[i].indexOf("@") == -1 || bcc[i].indexOf(".") == -1) {
299 continue;
300 }
301 v.addElement(bcc[i]);
302 }
303 String users[] = new String[v.size()];
304 for(int i = 0;i < v.size();i++) {
305 users[i] = (String)v.elementAt(i);
306 }
307 if(users.length == 0) {
308 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown recipient email address.", CmsException.C_BAD_NAME);
309 }
310 c_BCC = users;
311 }
312
313 /**
314 * Create a new email object with given FROM, TO and BCC addresses.
315 *
316 * @see #CmsMail(CmsObject,String, String[], String, String, String)
317 *
318 * @param cms Cms object.
319 * @param from Address of sender.
320 * @param to Address of recipient.
321 * @param cc Address of copy recipient.
322 * @param isBcc dedined wheather the type of cc is a bcc or not.
323 * @param subject Subject of email.
324 * @param content Content of email.
325 * @param type ContentType of email.
326 */
327 public CmsMail(CmsObject cms, String from, String[] to, String[] cc, boolean isBcc, String subject, String content, String type) throws CmsException {
328 this(cms, from, to, subject, content, type);
329 Vector v = new Vector();
330 for(int i = 0;i < cc.length;i++) {
331 if(cc[i] == null) {
332 continue;
333 }
334 if(cc[i].equals("")) {
335 continue;
336 }
337 if(cc[i].indexOf("@") == -1 || cc[i].indexOf(".") == -1) {
338 continue;
339 }
340 v.addElement(cc[i]);
341 }
342 String users[] = new String[v.size()];
343 for(int i = 0;i < v.size();i++) {
344 users[i] = (String)v.elementAt(i);
345 }
346 if(users.length == 0) {
347 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown recipient email address.", CmsException.C_BAD_NAME);
348 }
349 if (isBcc)
350 c_BCC = users;
351 else
352 c_CC=users;
353 }
354
355 /**
356 * Create a new email object with given FROM and TO addresses.
357 *
358 * @param cms Cms object.
359 * @param from Address of sender.
360 * @param to Array with address(es) of recipient(s).
361 * @param subject Subject of email.
362 * @param content Content of email.
363 * @param type ContentType of email.
364 */
365 public CmsMail(CmsObject cms, String from, String[] to, String subject, String content, String type) throws CmsException {
366
367 // check sender email address
368 if(from == null) {
369 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown sender email address.", CmsException.C_BAD_NAME);
370 }
371 if(from.equals("")) {
372 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown sender email address.", CmsException.C_BAD_NAME);
373 }
374 if(from.indexOf("@") == -1 || from.indexOf(".") == -1) {
375 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown sender email address: " + from, CmsException.C_BAD_NAME);
376 }
377
378 // check recipient email address
379 Vector v = new Vector(to.length);
380 for(int i = 0;i < to.length;i++) {
381 if(to[i] == null) {
382 continue;
383 }
384 if(to[i].equals("")) {
385 continue;
386 }
387 if(to[i].indexOf("@") == -1 || to[i].indexOf(".") == -1) {
388 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email, Invalid recipient email address: " + to[i], CmsException.C_BAD_NAME);
389 }
390 v.addElement(to[i]);
391 }
392 String users[] = new String[v.size()];
393 for(int i = 0;i < v.size();i++) {
394 users[i] = (String)v.elementAt(i);
395 }
396 if(users.length == 0) {
397 throw new CmsException("[" + this.getClass().getName() + "] " + "Error in sending email,Unknown recipient email address.", CmsException.C_BAD_NAME);
398 }
399 c_FROM = from;
400 c_TO = users;
401 c_SUBJECT = (subject == null ? "" : subject);
402 c_CONTENT = (content == null ? "" : content);
403 I_CmsRegistry reg = com.opencms.core.OpenCms.getRegistry();
404 c_MAILSERVER = reg.getSystemValue("smtpserver");
405 c_ALTERNATIVE_MAILSERVER = reg.getSystemValue("smtpserver2");
406 c_TYPE = type;
407 c_CMS = cms;
408 }
409
410 /**
411 * Add a new attachment of the given content type to this <code>CmsMail</code>
412 * object. The attachment will get a random name.
413 *
414 * @param content Content of the attachment.
415 * @param type Content type of the attachment.
416 */
417 public void addAttachment(String content, String type) {
418 attachContent.addElement(content);
419 attachType.addElement(type);
420 }
421
422 /**
423 * Internal method for building a new <code>MimeMessage</code> object
424 * with the given content, attachments, SMTP host properties, FROM, TO,
425 * CC and BCC addresses.
426 * Will be called from the thread connecting to the SMTP server
427 * and sending the mail.
428 * @param smtpHost Name of the SMTP host that should be connected.
429 * @return <code>Message</code> object that can be used as argument for the <code>Transport</code> class.
430 * @throws No exceptions occuring while building the mail will be caught.
431 */
432 private Message buildMessage(String smtpHost) throws Exception {
433
434 // Default encoding for new mail message
435 String mail_encoding = "ISO-8859-1";
436
437 // First check the smtpHost parameter
438 if(smtpHost == null || "".equals(smtpHost)) {
439 throw new CmsException("No SMTP server given.");
440 }
441
442 // create some properties and get the default Session
443 Properties props = System.getProperties();
444 props.put("mail.smtp.host", smtpHost);
445 Session session = Session.getDefaultInstance(props, null);
446
447 // Build a new message object
448 MimeMessage msg = new MimeMessage(session);
449
450 // Check and set all addresses.
451 InternetAddress[] to = new InternetAddress[c_TO.length];
452 for(int i = 0;i < c_TO.length;i++) {
453 to[i] = new InternetAddress(c_TO[i]);
454 }
455 msg.setFrom(new InternetAddress(c_FROM));
456 msg.setRecipients(Message.RecipientType.TO, to);
457 InternetAddress[] cc = null;
458 if(c_CC != null) {
459 cc = new InternetAddress[c_CC.length];
460 for(int i = 0;i < c_CC.length;i++) {
461 cc[i] = new InternetAddress(c_CC[i]);
462 }
463 msg.setRecipients(Message.RecipientType.CC, cc);
464 }
465 InternetAddress[] bcc = null;
466 if(c_BCC != null) {
467 bcc = new InternetAddress[c_BCC.length];
468 for(int i = 0;i < c_BCC.length;i++) {
469 bcc[i] = new InternetAddress(c_BCC[i]);
470 }
471 msg.setRecipients(Message.RecipientType.BCC, bcc);
472 }
473
474 // Set subject
475 msg.setSubject(c_SUBJECT, mail_encoding);
476
477 // Set content and attachments
478 Vector v = new Vector();
479 if (c_CMS != null){
480 Enumeration enum = c_CMS.getRequestContext().getRequest().getFileNames();
481 while(enum.hasMoreElements()) {
482 v.addElement(enum.nextElement());
483 }
484 }
485 int size = v.size();
486 int numAttach = attachContent.size();
487 if(size != 0 || numAttach != 0) {
488
489 // create and fill the first message part
490 MimeBodyPart mbp1 = new MimeBodyPart();
491 Multipart mp = new MimeMultipart();
492 if(c_TYPE.equals("text/html")) {
493 mbp1.setDataHandler(new DataHandler(new CmsByteArrayDataSource(c_CONTENT, c_TYPE, mail_encoding)));
494 }
495 else {
496 mbp1.setText(c_CONTENT, mail_encoding);
497 }
498 mp.addBodyPart(mbp1);
499
500 // Check, if there are any attachments
501 for(int i = 0;i < numAttach;i++) {
502
503 // create another message part
504 // attach the file to the message
505 MimeBodyPart mbpAttach = new MimeBodyPart();
506 if("text/html".equals((String)attachType.elementAt(i))) {
507 mbpAttach.setDataHandler(new DataHandler(new CmsByteArrayDataSource((String)attachContent.elementAt(i), "text/html", mail_encoding)));
508 }
509 else {
510 mbpAttach.setText((String)attachContent.elementAt(i), mail_encoding);
511 }
512 mp.addBodyPart(mbpAttach);
513 }
514 for(int i = 0;i < size;i++) {
515 String filename = (String)v.elementAt(i);
516 if (!"unknown".equalsIgnoreCase(filename)) {
517 MimetypesFileTypeMap mimeTypeMap = new MimetypesFileTypeMap();
518 String mimeType = mimeTypeMap.getContentType(filename);
519 MimeBodyPart mbp = new MimeBodyPart();
520 mbp.setDataHandler(new DataHandler(new CmsByteArrayDataSource(c_CMS.getRequestContext().getRequest().getFile(filename), mimeType)));
521 mbp.setFileName(filename);
522 mp.addBodyPart(mbp);
523 }
524 }
525 msg.setContent(mp);
526 }
527 else {
528 if(c_TYPE.equals("text/html")) {
529 msg.setDataHandler(new DataHandler(new CmsByteArrayDataSource(c_CONTENT, c_TYPE, mail_encoding)));
530 }
531 else {
532 msg.setContent(c_CONTENT, c_TYPE);
533 }
534 }
535 msg.setSentDate(new Date());
536 return msg;
537 }
538
539 /**
540 * Helper method for printing nice classnames in error messages
541 * @return class name in [ClassName] format
542 */
543 protected String getClassName() {
544 String name = getClass().getName();
545 return "[" + name.substring(name.lastIndexOf(".") + 1) + "] ";
546 }
547
548 /**
549 * Try sending the mail.
550 * This can take a few seconds to several minutes. We don't want
551 * the user to wait for the response of the current HTTP request.
552 * Therefore we are running this in a new thread. The user will
553 * get his response immediately, then.
554 */
555 public void run() {
556
557 // Build the message
558 Message msg = null;
559 try {
560 msg = buildMessage(c_MAILSERVER);
561 }
562 catch(Exception e) {
563 if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
564 A_OpenCms.log(C_OPENCMS_CRITICAL, getClassName() + "Error while building Email object: " + Utils.getStackTrace(e));
565 }
566
567 // Do not continue here. We don't have a Message object we can send.
568 return ;
569 }
570
571 // Now the message is ready.
572 // Try to send it...
573 try {
574 Transport.send(msg);
575 }
576 catch(Exception e) {
577
578 // Emergency! An error occured while connecting to the SMTP server
579 // We cannot inform the user at this point since this code runs
580 // in a thread and the initiating request is completed for a long time.
581 // Get nested Exception used for pretty printed error message in logfile
582 for(;e instanceof MessagingException;e = ((MessagingException)e).getNextException()) {
583 ;
584 }
585
586 // First print out an error message...
587 if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
588 A_OpenCms.log(C_OPENCMS_CRITICAL, getClassName() + "Error while transmitting mail to SMTP server: " + e);
589 }
590
591 // ... and now try an alternative server (if given)
592 if(c_ALTERNATIVE_MAILSERVER != null && !"".equals(c_ALTERNATIVE_MAILSERVER)) {
593 if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
594 A_OpenCms.log(C_OPENCMS_CRITICAL, getClassName() + "Trying alternative server...");
595 }
596 try {
597 msg = buildMessage(c_ALTERNATIVE_MAILSERVER);
598 Transport.send(msg);
599 if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
600 A_OpenCms.log(C_OPENCMS_CRITICAL, getClassName() + "...OK. Mail sent.");
601 }
602 }
603 catch(Exception e2) {
604
605 // Get nested Exception used for pretty printed error message in logfile
606 for(;e2 instanceof MessagingException;e2 = ((MessagingException)e2).getNextException()) {
607 ;
608 }
609 if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
610 A_OpenCms.log(C_OPENCMS_CRITICAL, getClassName() + "PANIC! Could not send Email. Even alternative server failed! " + e2);
611 }
612 }
613 }
614 else {
615 if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
616 A_OpenCms.log(C_OPENCMS_CRITICAL, getClassName() + "PANIC! No alternative SMTP server given! Could not send Email!");
617 }
618 }
619 }
620 }
621 }