Added feature #15998: Create a new API to send mails based on SwiftMailer to replace...
[Packages/TYPO3.CMS.git] / t3lib / mail / class.t3lib_mail_message.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Ernesto Baschny <ernst@cron-it.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 require_once(PATH_typo3.'contrib/swiftmailer/swift_required.php');
29
30
31 /**
32 * Adapter for Swift_Mailer to be used by TYPO3 extensions
33 *
34 * $Id$
35 *
36 * @author Ernesto Baschny <ernst@cron-it.de>
37 * @package TYPO3
38 * @subpackage t3lib
39 */
40 class t3lib_mail_message extends Swift_Message {
41
42 /**
43 * @var t3lib_mail_mailer
44 */
45 var $mailer;
46
47 /**
48 * True if the message has been sent.
49 * @var boolean
50 */
51 var $sent = FALSE;
52
53 /**
54 * Holds the failed recipients after the message has been sent
55 * @var array
56 */
57 var $failedRecipients = array();
58
59 /**
60 *
61 * @return void
62 */
63 private function initializeMailer() {
64 $this->mailer = t3lib_div::makeInstance('t3lib_mail_mailer');
65 }
66
67 /**
68 * Sends the message.
69 *
70 * @return integer the number of recipients who were accepted for delivery
71 * @author Karsten Dambekalns <karsten@typo3.org>
72 */
73 public function send() {
74 $this->initializeMailer();
75 $this->sent = TRUE;
76 return $this->mailer->send($this, &$this->failedRecipients);
77 }
78
79 /**
80 * Checks whether the message has been sent.
81 *
82 * @return boolean
83 * @author Karsten Dambekalns <karsten@typo3.org>
84 */
85 public function isSent() {
86 return $this->sent;
87 }
88
89 /**
90 * Returns the recipients for which the mail was not accepted for delivery.
91 *
92 * @return array the recipients who were not accepted for delivery
93 * @author Karsten Dambekalns <karsten@typo3.org>
94 */
95 public function getFailedRecipients() {
96 return $this->failedRecipients;
97 }
98
99 }
100
101 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_mail_message.php']) {
102 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_mail_message.php']);
103 }
104
105 ?>