Version Notes
Support for sending email using all configuration types available in Zend Mail.
Created by Kalpesh Balar, kalpeshbalar.com.
Download this release
Release Info
Developer | Kalpesh Balar |
Extension | Ralab_SMTP |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Ralab/Smtp/Helper/Data.php +65 -0
- app/code/community/Ralab/Smtp/Model/Email.php +37 -0
- app/code/community/Ralab/Smtp/Model/Email/Queue.php +92 -0
- app/code/community/Ralab/Smtp/Model/Email/Template.php +112 -0
- app/code/community/Ralab/Smtp/Model/System/Config/Source/Smtp/Authentication.php +24 -0
- app/code/community/Ralab/Smtp/Model/System/Config/Source/Smtp/Ssl.php +23 -0
- app/code/community/Ralab/Smtp/Model/Template.php +94 -0
- app/code/community/Ralab/Smtp/etc/config.xml +48 -0
- app/code/community/Ralab/Smtp/etc/system.xml +60 -0
- app/etc/modules/Ralab_Smtp.xml +9 -0
- package.xml +26 -0
app/code/community/Ralab/Smtp/Helper/Data.php
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* @package Ralab_Smtp
|
5 |
+
* @author Kalpesh Balar <kalpeshbalar@gmail.com>
|
6 |
+
* @copyright Ralab (http://ralab.in)
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
|
11 |
+
class Ralab_Smtp_Helper_Data extends Mage_Core_Helper_Abstract
|
12 |
+
{
|
13 |
+
public function getSMTPAuth($storeId = null)
|
14 |
+
{
|
15 |
+
return Mage::getStoreConfig('system/smtp/smtp_auth', $storeId);
|
16 |
+
}
|
17 |
+
|
18 |
+
public function getSMTPHost($storeId = null)
|
19 |
+
{
|
20 |
+
return Mage::getStoreConfig('system/smtp/host', $storeId);
|
21 |
+
}
|
22 |
+
|
23 |
+
public function getSMTPPort($storeId = null)
|
24 |
+
{
|
25 |
+
return Mage::getStoreConfig('system/smtp/port', $storeId);
|
26 |
+
}
|
27 |
+
|
28 |
+
public function getSMTPUsername($storeId = null)
|
29 |
+
{
|
30 |
+
return Mage::getStoreConfig('system/smtp/smtp_username', $storeId);
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getSMTPPassword($storeId = null)
|
34 |
+
{
|
35 |
+
return Mage::getStoreConfig('system/smtp/smtp_password', $storeId);
|
36 |
+
}
|
37 |
+
|
38 |
+
public function getSMTPSSL($storeId = null)
|
39 |
+
{
|
40 |
+
return Mage::getStoreConfig('system/smtp/smtp_ssl', $storeId);
|
41 |
+
}
|
42 |
+
|
43 |
+
public function getTransport () {
|
44 |
+
|
45 |
+
$config = array();
|
46 |
+
|
47 |
+
$auth = $this->getSMTPAuth($storeId);
|
48 |
+
if ($auth != "none") {
|
49 |
+
$config['auth'] = $auth;
|
50 |
+
$config['username'] = $this->getSMTPUsername($storeId);
|
51 |
+
$config['password'] = $this->getSMTPPassword($storeId);
|
52 |
+
}
|
53 |
+
|
54 |
+
$config['port'] = $this->getSMTPPort($storeId);
|
55 |
+
|
56 |
+
$ssl = $this->getSMTPSSL($storeId);
|
57 |
+
if ($ssl != "none" ) {
|
58 |
+
$config['ssl'] = $ssl;
|
59 |
+
}
|
60 |
+
|
61 |
+
$host = $this->getSMTPHost($storeId);
|
62 |
+
$transport = new Zend_Mail_Transport_Smtp($host, $config);
|
63 |
+
return $transport;
|
64 |
+
}
|
65 |
+
}
|
app/code/community/Ralab/Smtp/Model/Email.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @package Ralab_Smtp
|
6 |
+
* @author Kalpesh Balar <kalpeshbalar@gmail.com>
|
7 |
+
* @copyright Ralab (http://ralab.in)
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
|
11 |
+
class Ralab_Smtp_Model_Email extends Mage_Core_Model_Email
|
12 |
+
{
|
13 |
+
public function send()
|
14 |
+
{
|
15 |
+
Mage::log(__METHOD__);
|
16 |
+
if (Mage::getStoreConfigFlag('system/smtp/disable')) {
|
17 |
+
return $this;
|
18 |
+
}
|
19 |
+
|
20 |
+
$mail = new Zend_Mail();
|
21 |
+
|
22 |
+
if (strtolower($this->getType()) == 'html') {
|
23 |
+
$mail->setBodyHtml($this->getBody());
|
24 |
+
}
|
25 |
+
else {
|
26 |
+
$mail->setBodyText($this->getBody());
|
27 |
+
}
|
28 |
+
|
29 |
+
$mail->setFrom($this->getFromEmail(), $this->getFromName())
|
30 |
+
->addTo($this->getToEmail(), $this->getToName())
|
31 |
+
->setSubject($this->getSubject());
|
32 |
+
//$mail->send();
|
33 |
+
$mail->send(Mage::helper('smtp')->getTransport());
|
34 |
+
|
35 |
+
return $this;
|
36 |
+
}
|
37 |
+
}
|
app/code/community/Ralab/Smtp/Model/Email/Queue.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @package Ralab_Smtp
|
6 |
+
* @author Kalpesh Balar <kalpeshbalar@gmail.com>
|
7 |
+
* @copyright Ralab (http://ralab.in)
|
8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Ralab_Smtp_Model_Email_Template extends Mage_Core_Model_Email_Queue
|
13 |
+
{
|
14 |
+
/**
|
15 |
+
* Send all messages in a queue
|
16 |
+
*
|
17 |
+
* @return Mage_Core_Model_Email_Queue
|
18 |
+
*/
|
19 |
+
public function send()
|
20 |
+
{
|
21 |
+
/** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
|
22 |
+
$collection = Mage::getModel('core/email_queue')->getCollection()
|
23 |
+
->addOnlyForSendingFilter()
|
24 |
+
->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN)
|
25 |
+
->setCurPage(1)
|
26 |
+
->load();
|
27 |
+
|
28 |
+
|
29 |
+
ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
|
30 |
+
ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
|
31 |
+
|
32 |
+
/** @var $message Mage_Core_Model_Email_Queue */
|
33 |
+
foreach ($collection as $message) {
|
34 |
+
if ($message->getId()) {
|
35 |
+
$parameters = new Varien_Object($message->getMessageParameters());
|
36 |
+
if ($parameters->getReturnPathEmail() !== null) {
|
37 |
+
$mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail());
|
38 |
+
Zend_Mail::setDefaultTransport($mailTransport);
|
39 |
+
}
|
40 |
+
|
41 |
+
$mailer = new Zend_Mail('utf-8');
|
42 |
+
foreach ($message->getRecipients() as $recipient) {
|
43 |
+
list($email, $name, $type) = $recipient;
|
44 |
+
switch ($type) {
|
45 |
+
case self::EMAIL_TYPE_BCC:
|
46 |
+
$mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?=');
|
47 |
+
break;
|
48 |
+
case self::EMAIL_TYPE_TO:
|
49 |
+
case self::EMAIL_TYPE_CC:
|
50 |
+
default:
|
51 |
+
$mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?=');
|
52 |
+
break;
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
if ($parameters->getIsPlain()) {
|
57 |
+
$mailer->setBodyText($message->getMessageBody());
|
58 |
+
} else {
|
59 |
+
$mailer->setBodyHTML($message->getMessageBody());
|
60 |
+
}
|
61 |
+
|
62 |
+
$mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?=');
|
63 |
+
$mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
|
64 |
+
if ($parameters->getReplyTo() !== null) {
|
65 |
+
$mailer->setReplyTo($parameters->getReplyTo());
|
66 |
+
}
|
67 |
+
if ($parameters->getReturnTo() !== null) {
|
68 |
+
$mailer->setReturnPath($parameters->getReturnTo());
|
69 |
+
}
|
70 |
+
|
71 |
+
try {
|
72 |
+
//$mailer->send();
|
73 |
+
$mailer->send(Mage::helper('smtp')->getTransport());
|
74 |
+
unset($mailer);
|
75 |
+
$message->setProcessedAt(Varien_Date::formatDate(true));
|
76 |
+
$message->save();
|
77 |
+
}
|
78 |
+
catch (Exception $e) {
|
79 |
+
unset($mailer);
|
80 |
+
$oldDevMode = Mage::getIsDeveloperMode();
|
81 |
+
Mage::setIsDeveloperMode(true);
|
82 |
+
Mage::logException($e);
|
83 |
+
Mage::setIsDeveloperMode($oldDevMode);
|
84 |
+
|
85 |
+
return false;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
return $this;
|
91 |
+
}
|
92 |
+
}
|
app/code/community/Ralab/Smtp/Model/Email/Template.php
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @package Ralab_Smtp
|
6 |
+
* @author Kalpesh Balar <kalpeshbalar@gmail.com>
|
7 |
+
* @copyright Ralab (http://ralab.in)
|
8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Ralab_Smtp_Model_Email_Template extends Mage_Core_Model_Email_Template
|
13 |
+
{
|
14 |
+
/**
|
15 |
+
* Send mail to recipient
|
16 |
+
*
|
17 |
+
* @param array|string $email E-mail(s)
|
18 |
+
* @param array|string|null $name receiver name(s)
|
19 |
+
* @param array $variables template variables
|
20 |
+
* @return boolean
|
21 |
+
**/
|
22 |
+
public function send($email, $name = null, array $variables = array())
|
23 |
+
{
|
24 |
+
if (!$this->isValidForSend()) {
|
25 |
+
Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
|
26 |
+
return false;
|
27 |
+
}
|
28 |
+
|
29 |
+
$emails = array_values((array)$email);
|
30 |
+
$names = is_array($name) ? $name : (array)$name;
|
31 |
+
$names = array_values($names);
|
32 |
+
foreach ($emails as $key => $email) {
|
33 |
+
if (!isset($names[$key])) {
|
34 |
+
$names[$key] = substr($email, 0, strpos($email, '@'));
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
$variables['email'] = reset($emails);
|
39 |
+
$variables['name'] = reset($names);
|
40 |
+
|
41 |
+
$this->setUseAbsoluteLinks(true);
|
42 |
+
$text = $this->getProcessedTemplate($variables, true);
|
43 |
+
$subject = $this->getProcessedTemplateSubject($variables);
|
44 |
+
|
45 |
+
$setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
|
46 |
+
switch ($setReturnPath) {
|
47 |
+
case 1:
|
48 |
+
$returnPathEmail = $this->getSenderEmail();
|
49 |
+
break;
|
50 |
+
case 2:
|
51 |
+
$returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
|
52 |
+
break;
|
53 |
+
default:
|
54 |
+
$returnPathEmail = null;
|
55 |
+
break;
|
56 |
+
}
|
57 |
+
|
58 |
+
if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
|
59 |
+
$emailQueue = $this->getQueue();
|
60 |
+
$emailQueue->setMessageBody($text);
|
61 |
+
$emailQueue->setMessageParameters(array(
|
62 |
+
'subject' => $subject,
|
63 |
+
'return_path_email' => $returnPathEmail,
|
64 |
+
'is_plain' => $this->isPlain(),
|
65 |
+
'from_email' => $this->getSenderEmail(),
|
66 |
+
'from_name' => $this->getSenderName(),
|
67 |
+
'reply_to' => $this->getMail()->getReplyTo(),
|
68 |
+
'return_to' => $this->getMail()->getReturnPath(),
|
69 |
+
))
|
70 |
+
->addRecipients($emails, $names, Mage_Core_Model_Email_Queue::EMAIL_TYPE_TO)
|
71 |
+
->addRecipients($this->_bccEmails, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC);
|
72 |
+
$emailQueue->addMessageToQueue();
|
73 |
+
|
74 |
+
return true;
|
75 |
+
}
|
76 |
+
|
77 |
+
ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
|
78 |
+
ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
|
79 |
+
|
80 |
+
$mail = $this->getMail();
|
81 |
+
|
82 |
+
if ($returnPathEmail !== null) {
|
83 |
+
$mailTransport = new Zend_Mail_Transport_Sendmail("-f".$returnPathEmail);
|
84 |
+
Zend_Mail::setDefaultTransport($mailTransport);
|
85 |
+
}
|
86 |
+
|
87 |
+
foreach ($emails as $key => $email) {
|
88 |
+
$mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
|
89 |
+
}
|
90 |
+
|
91 |
+
if ($this->isPlain()) {
|
92 |
+
$mail->setBodyText($text);
|
93 |
+
} else {
|
94 |
+
$mail->setBodyHTML($text);
|
95 |
+
}
|
96 |
+
|
97 |
+
$mail->setSubject('=?utf-8?B?' . base64_encode($subject) . '?=');
|
98 |
+
$mail->setFrom($this->getSenderEmail(), $this->getSenderName());
|
99 |
+
|
100 |
+
try {
|
101 |
+
$mail->send(Mage::helper('smtp')->getTransport());
|
102 |
+
$this->_mail = null;
|
103 |
+
}
|
104 |
+
catch (Exception $e) {
|
105 |
+
$this->_mail = null;
|
106 |
+
Mage::logException($e);
|
107 |
+
return false;
|
108 |
+
}
|
109 |
+
|
110 |
+
return true;
|
111 |
+
}
|
112 |
+
}
|
app/code/community/Ralab/Smtp/Model/System/Config/Source/Smtp/Authentication.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @package Ralab_Smtp
|
6 |
+
* @author Kalpesh Balar <kalpeshbalar@gmail.com>
|
7 |
+
* @copyright Ralab (http://ralab.in)
|
8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Ralab_Smtp_Model_System_Config_Source_Smtp_Authentication
|
13 |
+
{
|
14 |
+
public function toOptionArray()
|
15 |
+
{
|
16 |
+
//http://framework.zend.com/manual/current/en/modules/zend.mail.smtp.options.html
|
17 |
+
return array(
|
18 |
+
"smtp" => Mage::helper('adminhtml')->__('None'),
|
19 |
+
"login" => Mage::helper('adminhtml')->__('Login'),
|
20 |
+
"plain" => Mage::helper('adminhtml')->__('Plain'),
|
21 |
+
"crammd5" => Mage::helper('adminhtml')->__('CRAM MD5')
|
22 |
+
);
|
23 |
+
}
|
24 |
+
}
|
app/code/community/Ralab/Smtp/Model/System/Config/Source/Smtp/Ssl.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @package Ralab_Smtp
|
6 |
+
* @author Kalpesh Balar <kalpeshbalar@gmail.com>
|
7 |
+
* @copyright Ralab (http://ralab.in)
|
8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Ralab_Smtp_Model_System_Config_Source_Smtp_Ssl
|
13 |
+
{
|
14 |
+
public function toOptionArray()
|
15 |
+
{
|
16 |
+
// http://framework.zend.com/manual/current/en/modules/zend.mail.smtp.options.html
|
17 |
+
return array(
|
18 |
+
"none" => Mage::helper('adminhtml')->__('None'),
|
19 |
+
"ssl" => Mage::helper('adminhtml')->__('SSL'),
|
20 |
+
"tls" => Mage::helper('adminhtml')->__('TLS')
|
21 |
+
);
|
22 |
+
}
|
23 |
+
}
|
app/code/community/Ralab/Smtp/Model/Template.php
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @package Ralab_Smtp
|
6 |
+
* @author Kalpesh Balar <kalpeshbalar@gmail.com>
|
7 |
+
* @copyright Ralab (http://ralab.in)
|
8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
|
12 |
+
class Ralab_Smtp_Model_Template extends Mage_Newsletter_Model_Template
|
13 |
+
{
|
14 |
+
/**
|
15 |
+
* Send mail to subscriber
|
16 |
+
*
|
17 |
+
* @param Mage_Newsletter_Model_Subscriber|string $subscriber subscriber Model or E-mail
|
18 |
+
* @param array $variables template variables
|
19 |
+
* @param string|null $name receiver name (if subscriber model not specified)
|
20 |
+
* @param Mage_Newsletter_Model_Queue|null $queue queue model, used for problems reporting.
|
21 |
+
* @return boolean
|
22 |
+
* @deprecated since 1.4.0.1
|
23 |
+
**/
|
24 |
+
public function send($subscriber, array $variables = array(), $name=null, Mage_Newsletter_Model_Queue $queue=null)
|
25 |
+
{
|
26 |
+
if (!$this->isValidForSend()) {
|
27 |
+
return false;
|
28 |
+
}
|
29 |
+
|
30 |
+
$email = '';
|
31 |
+
if ($subscriber instanceof Mage_Newsletter_Model_Subscriber) {
|
32 |
+
$email = $subscriber->getSubscriberEmail();
|
33 |
+
if (is_null($name) && ($subscriber->hasCustomerFirstname() || $subscriber->hasCustomerLastname()) ) {
|
34 |
+
$name = $subscriber->getCustomerFirstname() . ' ' . $subscriber->getCustomerLastname();
|
35 |
+
}
|
36 |
+
}
|
37 |
+
else {
|
38 |
+
$email = (string) $subscriber;
|
39 |
+
}
|
40 |
+
|
41 |
+
if (Mage::getStoreConfigFlag(Mage_Core_Model_Email_Template::XML_PATH_SENDING_SET_RETURN_PATH)) {
|
42 |
+
$this->getMail()->setReturnPath($this->getTemplateSenderEmail());
|
43 |
+
}
|
44 |
+
|
45 |
+
ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
|
46 |
+
ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
|
47 |
+
|
48 |
+
$mail = $this->getMail();
|
49 |
+
$mail->addTo($email, $name);
|
50 |
+
$text = $this->getProcessedTemplate($variables, true);
|
51 |
+
|
52 |
+
if ($this->isPlain()) {
|
53 |
+
$mail->setBodyText($text);
|
54 |
+
}
|
55 |
+
else {
|
56 |
+
$mail->setBodyHTML($text);
|
57 |
+
}
|
58 |
+
|
59 |
+
$mail->setSubject($this->getProcessedTemplateSubject($variables));
|
60 |
+
$mail->setFrom($this->getTemplateSenderEmail(), $this->getTemplateSenderName());
|
61 |
+
|
62 |
+
try {
|
63 |
+
//$mail->send();
|
64 |
+
$mail->send(Mage::helper('smtp')->getTransport());
|
65 |
+
|
66 |
+
$this->_mail = null;
|
67 |
+
if (!is_null($queue)) {
|
68 |
+
$subscriber->received($queue);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
catch (Exception $e) {
|
72 |
+
if ($subscriber instanceof Mage_Newsletter_Model_Subscriber) {
|
73 |
+
// If letter sent for subscriber, we create a problem report entry
|
74 |
+
$problem = Mage::getModel('newsletter/problem');
|
75 |
+
$problem->addSubscriberData($subscriber);
|
76 |
+
if (!is_null($queue)) {
|
77 |
+
$problem->addQueueData($queue);
|
78 |
+
}
|
79 |
+
$problem->addErrorData($e);
|
80 |
+
$problem->save();
|
81 |
+
|
82 |
+
if (!is_null($queue)) {
|
83 |
+
$subscriber->received($queue);
|
84 |
+
}
|
85 |
+
} else {
|
86 |
+
// Otherwise throw error to upper level
|
87 |
+
throw $e;
|
88 |
+
}
|
89 |
+
return false;
|
90 |
+
}
|
91 |
+
|
92 |
+
return true;
|
93 |
+
}
|
94 |
+
}
|
app/code/community/Ralab/Smtp/etc/config.xml
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @package Ralab_Smtp
|
6 |
+
* @author Kalpesh Balar <kalpeshbalar@gmail.com>
|
7 |
+
* @copyright Ralab (http://ralab.in)
|
8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
-->
|
12 |
+
<config>
|
13 |
+
<modules>
|
14 |
+
<Ralab_Smtp>
|
15 |
+
<version>1.0.0</version>
|
16 |
+
</Ralab_Smtp>
|
17 |
+
</modules>
|
18 |
+
<global>
|
19 |
+
<helpers>
|
20 |
+
<smtp><class>Ralab_Smtp_Helper</class></smtp>
|
21 |
+
</helpers>
|
22 |
+
<models>
|
23 |
+
<smtp>
|
24 |
+
<class>Ralab_Smtp_Model</class>
|
25 |
+
</smtp>
|
26 |
+
<core>
|
27 |
+
<rewrite>
|
28 |
+
<email>Ralab_Smtp_Model_Email</email>
|
29 |
+
<email_queue>Ralab_Smtp_Model_Email_Queue</email_queue>
|
30 |
+
<email_template>Ralab_Smtp_Model_Email_Template</email_template>
|
31 |
+
</rewrite>
|
32 |
+
</core>
|
33 |
+
<newsletter>
|
34 |
+
<rewrite>
|
35 |
+
<template>Ralab_Smtp_Model_Template</template>
|
36 |
+
</rewrite>
|
37 |
+
</newsletter>
|
38 |
+
</models>
|
39 |
+
</global>
|
40 |
+
<default>
|
41 |
+
<system>
|
42 |
+
<smtp>
|
43 |
+
<smtp_username></smtp_username>
|
44 |
+
<smtp_password backend_model="adminhtml/system_config_backend_encrypted" />
|
45 |
+
</smtp>
|
46 |
+
</system>
|
47 |
+
</default>
|
48 |
+
</config>
|
app/code/community/Ralab/Smtp/etc/system.xml
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
*
|
5 |
+
* @package Ralab_Smtp
|
6 |
+
* @author Kalpesh Balar <kalpeshbalar@gmail.com>
|
7 |
+
* @copyright Ralab (http://ralab.in)
|
8 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
-->
|
12 |
+
<config>
|
13 |
+
<sections>
|
14 |
+
<system>
|
15 |
+
<groups>
|
16 |
+
<smtp translate="label" module="smtp">
|
17 |
+
<fields>
|
18 |
+
<smtp_auth translate="label">
|
19 |
+
<label>Authentication</label>
|
20 |
+
<frontend_type>select</frontend_type>
|
21 |
+
<source_model>smtp/system_config_source_smtp_authentication</source_model>
|
22 |
+
<sort_order>20</sort_order>
|
23 |
+
<show_in_default>1</show_in_default>
|
24 |
+
<show_in_website>1</show_in_website>
|
25 |
+
<show_in_store>0</show_in_store>
|
26 |
+
</smtp_auth>
|
27 |
+
<smtp_username translate="label">
|
28 |
+
<label>Username</label>
|
29 |
+
<frontend_type>text</frontend_type>
|
30 |
+
<sort_order>35</sort_order>
|
31 |
+
<show_in_default>1</show_in_default>
|
32 |
+
<show_in_website>1</show_in_website>
|
33 |
+
<show_in_store>0</show_in_store>
|
34 |
+
<depends><smtp_auth separator=",">login,plain,crammd5</smtp_auth></depends>
|
35 |
+
</smtp_username>
|
36 |
+
<smtp_password translate="label">
|
37 |
+
<label>Password</label>
|
38 |
+
<frontend_type>password</frontend_type>
|
39 |
+
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
|
40 |
+
<sort_order>40</sort_order>
|
41 |
+
<show_in_default>1</show_in_default>
|
42 |
+
<show_in_website>1</show_in_website>
|
43 |
+
<show_in_store>0</show_in_store>
|
44 |
+
<depends><smtp_auth separator=",">login,plain,crammd5</smtp_auth></depends>
|
45 |
+
</smtp_password>
|
46 |
+
<smtp_ssl translate="label comment">
|
47 |
+
<label>SSL Security</label>
|
48 |
+
<frontend_type>select</frontend_type>
|
49 |
+
<source_model>smtp/system_config_source_smtp_ssl</source_model>
|
50 |
+
<sort_order>45</sort_order>
|
51 |
+
<show_in_default>1</show_in_default>
|
52 |
+
<show_in_website>1</show_in_website>
|
53 |
+
<show_in_store>0</show_in_store>
|
54 |
+
</smtp_ssl>
|
55 |
+
</fields>
|
56 |
+
</smtp>
|
57 |
+
</groups>
|
58 |
+
</system>
|
59 |
+
</sections>
|
60 |
+
</config>
|
app/etc/modules/Ralab_Smtp.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Ralab_Smtp>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Ralab_Smtp>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Ralab_SMTP</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Simple SMTP is the an open source magento extension to Authenticate with any SMTP Server.</summary>
|
10 |
+
<description>Simple SMTP - Simple SMTP Authentication
|
11 |
+

|
12 |
+
Simple SMTP Pro is a free open source SMTP solution for Magento. It supports all configuration types available in Zend_Mail.
|
13 |
+

|
14 |
+
http://framework.zend.com/manual/current/en/modules/zend.mail.smtp.options.html
|
15 |
+

|
16 |
+
This extension is completely Open Source.</description>
|
17 |
+
<notes>Support for sending email using all configuration types available in Zend Mail.
|
18 |
+

|
19 |
+
Created by Kalpesh Balar, kalpeshbalar.com.</notes>
|
20 |
+
<authors><author><name>Kalpesh Balar</name><user>kalpeshbalar</user><email>kalpeshbalar@gmail.com</email></author></authors>
|
21 |
+
<date>2015-03-09</date>
|
22 |
+
<time>12:44:10</time>
|
23 |
+
<contents><target name="magecommunity"><dir name="Ralab"><dir name="Smtp"><dir name="Helper"><file name="Data.php" hash="efd398dda5a9608bde45b8de7ea8e1d7"/></dir><dir name="Model"><dir name="Email"><file name="Queue.php" hash="e47a8d070ae046d03185a89d75ffacc8"/><file name="Template.php" hash="e367f3eb54075118c28553ea8c41b25b"/></dir><file name="Email.php" hash="7972de4c6d5fc6ebc5710482d67f3a93"/><dir name="System"><dir name="Config"><dir name="Source"><dir name="Smtp"><file name="Authentication.php" hash="0216b4b20765b19051bf230096844983"/><file name="Ssl.php" hash="ed970cfb4d2c7064dbb9af15dccbccbf"/></dir></dir></dir></dir><file name="Template.php" hash="b8c04542b809acce613c212920bc03f8"/></dir><dir name="etc"><file name="config.xml" hash="842ba63ab476f868a27840a119146017"/><file name="system.xml" hash="f4e2a49d72360d9673fef9c904c87b82"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ralab_Smtp.xml" hash="27509e8466b39932208a7fffc0e1dbeb"/></dir></target></contents>
|
24 |
+
<compatible/>
|
25 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
26 |
+
</package>
|