Version Notes
- One of our owners was a partner in Round3Media, this is an update released by SUMO Heavy Industries
- Now supports Bcc
- Refactored code, better documentation
- Moved the main Postmark class to /lib (ZF)
Download this release
Release Info
| Developer | Robert Brodie |
| Extension | Round3media_Postmark |
| Version | 2.0.0 |
| Comparing to | |
| See all releases | |
Code changes from version 1.3.0 to 2.0.0
- app/code/community/Round3media/Postmark/Helper/Data.php +0 -25
- app/code/community/Round3media/Postmark/Model/Email.php +0 -24
- app/code/community/Round3media/Postmark/Model/Email/Template.php +0 -81
- app/code/community/Round3media/Postmark/etc/config.xml +0 -73
- app/code/community/Round3media/Postmark/etc/system.xml +0 -59
- app/code/community/SUMOHeavy/Postmark/Helper/Data.php +24 -0
- app/code/community/SUMOHeavy/Postmark/Model/Core/Email/Template.php +90 -0
- app/code/community/SUMOHeavy/Postmark/etc/config.xml +75 -0
- app/code/community/SUMOHeavy/Postmark/etc/system.xml +64 -0
- app/etc/modules/{Round3media_Postmark.xml → SUMOHeavy_Postmark.xml} +10 -9
- lib/SUMOHeavy/Mail/Transport/Postmark.php +341 -0
- package.xml +16 -12
app/code/community/Round3media/Postmark/Helper/Data.php
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* round3media
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
-
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
-
* It is also available through the world-wide-web at this URL:
|
| 10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
-
* If you did not receive a copy of the license and are unable to
|
| 12 |
-
* obtain it through the world-wide-web, please send an email
|
| 13 |
-
* to info@round3media.com so we can send you a copy immediately.
|
| 14 |
-
*
|
| 15 |
-
* @category Round3media
|
| 16 |
-
* @package Round3media_Postmark
|
| 17 |
-
* @copyright Copyright (c) 2009 round3media, LLC
|
| 18 |
-
* @notice The Postmark logo and name are trademarks of Wildbit, LLC
|
| 19 |
-
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
-
*/
|
| 21 |
-
|
| 22 |
-
class Round3media_Postmark_Helper_Data extends Mage_Core_Helper_Abstract
|
| 23 |
-
{
|
| 24 |
-
|
| 25 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Round3media/Postmark/Model/Email.php
DELETED
|
@@ -1,24 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* round3media
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
-
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
-
* It is also available through the world-wide-web at this URL:
|
| 10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
-
* If you did not receive a copy of the license and are unable to
|
| 12 |
-
* obtain it through the world-wide-web, please send an email
|
| 13 |
-
* to info@round3media.com so we can send you a copy immediately.
|
| 14 |
-
*
|
| 15 |
-
* @category Round3media
|
| 16 |
-
* @package Round3media_Postmark
|
| 17 |
-
* @copyright Copyright (c) 2009 round3media, LLC
|
| 18 |
-
* @notice The Postmark logo and name are trademarks of Wildbit, LLC
|
| 19 |
-
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
-
*/
|
| 21 |
-
class Round3media_Postmark_Model_Email extends Mage_Core_Model_Email
|
| 22 |
-
{
|
| 23 |
-
|
| 24 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Round3media/Postmark/Model/Email/Template.php
DELETED
|
@@ -1,81 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* round3media
|
| 4 |
-
*
|
| 5 |
-
* NOTICE OF LICENSE
|
| 6 |
-
*
|
| 7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
-
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
-
* It is also available through the world-wide-web at this URL:
|
| 10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
-
* If you did not receive a copy of the license and are unable to
|
| 12 |
-
* obtain it through the world-wide-web, please send an email
|
| 13 |
-
* to info@round3media.com so we can send you a copy immediately.
|
| 14 |
-
*
|
| 15 |
-
* @category Round3media
|
| 16 |
-
* @package Round3media_Postmark
|
| 17 |
-
* @copyright Copyright (c) 2009 round3media, LLC
|
| 18 |
-
* @notice The Postmark logo and name are trademarks of Wildbit, LLC
|
| 19 |
-
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
-
*/
|
| 21 |
-
class Round3media_Postmark_Model_Email_Template extends Mage_Core_Model_Email_Template
|
| 22 |
-
{
|
| 23 |
-
public function send($email, $name=null, array $variables = array())
|
| 24 |
-
{
|
| 25 |
-
if (!Mage::getStoreConfig('postmark/settings/enabled'))
|
| 26 |
-
{
|
| 27 |
-
return parent::send($email, $name, $variables);
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
if (is_null($name)) {
|
| 31 |
-
$name = substr($email, 0, strpos($email, '@'));
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
$variables['email'] = $email;
|
| 35 |
-
$variables['name'] = $name;
|
| 36 |
-
|
| 37 |
-
$this->setUseAbsoluteLinks(true);
|
| 38 |
-
$text = $this->getProcessedTemplate($variables, true);
|
| 39 |
-
|
| 40 |
-
if($this->isPlain()) {
|
| 41 |
-
$plain_body = $text;
|
| 42 |
-
} else {
|
| 43 |
-
$html_body = $text;
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
$from = $this->getSenderEmail();
|
| 47 |
-
$fromName = $this->getSenderName();
|
| 48 |
-
$to = $email;
|
| 49 |
-
$subject = $this->getProcessedTemplateSubject($variables);
|
| 50 |
-
|
| 51 |
-
$url = 'http://api.postmarkapp.com/email';
|
| 52 |
-
|
| 53 |
-
$apikey = Mage::getStoreConfig('postmark/settings/apikey');
|
| 54 |
-
|
| 55 |
-
$data = array (
|
| 56 |
-
'Subject' => $subject
|
| 57 |
-
);
|
| 58 |
-
|
| 59 |
-
$data['From'] = "$fromName <{$from}>";
|
| 60 |
-
$data['To'] = "$name <{$to}>";
|
| 61 |
-
|
| 62 |
-
$data['HtmlBody'] = $text;
|
| 63 |
-
$data['TextBody'] = $text;
|
| 64 |
-
|
| 65 |
-
$headers = array
|
| 66 |
-
(
|
| 67 |
-
"Accept: application/json",
|
| 68 |
-
"Content-Type: application/json",
|
| 69 |
-
"X-Postmark-Server-Token: " . $apikey
|
| 70 |
-
);
|
| 71 |
-
|
| 72 |
-
$handle_id = @curl_init();
|
| 73 |
-
@curl_setopt($handle_id, CURLOPT_URL, $url);
|
| 74 |
-
@curl_setopt($handle_id, CURLOPT_RETURNTRANSFER, true);
|
| 75 |
-
@curl_setopt($handle_id, CURLOPT_POST, true);
|
| 76 |
-
@curl_setopt($handle_id, CURLOPT_POSTFIELDS, json_encode($data));
|
| 77 |
-
@curl_setopt($handle_id, CURLOPT_HTTPHEADER, $headers);
|
| 78 |
-
@curl_exec($handle_id);
|
| 79 |
-
@curl_close($handle_id);
|
| 80 |
-
}
|
| 81 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Round3media/Postmark/etc/config.xml
DELETED
|
@@ -1,73 +0,0 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
<!-- /** * round3media * * NOTICE OF LICENSE * * This source file is subject
|
| 3 |
-
to the Open Software License (OSL 3.0) * that is bundled with this package
|
| 4 |
-
in the file LICENSE.txt. * It is also available through the world-wide-web
|
| 5 |
-
at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not
|
| 6 |
-
receive a copy of the license and are unable to * obtain it through the world-wide-web,
|
| 7 |
-
please send an email * to info@round3media.com so we can send you a copy
|
| 8 |
-
immediately. * * @category Round3media * @package Round3media_Postmark *
|
| 9 |
-
@copyright Copyright (c) 2009 round3media, LLC * @notice The Postmark logo
|
| 10 |
-
and name are trademarks of Wildbit, LLC * @license http://www.opensource.org/licenses/osl-3.0.php
|
| 11 |
-
Open Software License (OSL 3.0) */ -->
|
| 12 |
-
<config>
|
| 13 |
-
<modules>
|
| 14 |
-
<Round3media_Postmark>
|
| 15 |
-
<version>0.1.0</version>
|
| 16 |
-
</Round3media_Postmark>
|
| 17 |
-
</modules>
|
| 18 |
-
<global>
|
| 19 |
-
<models>
|
| 20 |
-
<core>
|
| 21 |
-
<rewrite>
|
| 22 |
-
<email_template>Round3media_Postmark_Model_Email_Template</email_template>
|
| 23 |
-
<email>Round3media_Postmark_Model_Email</email>
|
| 24 |
-
</rewrite>
|
| 25 |
-
</core>
|
| 26 |
-
</models>
|
| 27 |
-
<helpers>
|
| 28 |
-
<postmark>
|
| 29 |
-
<class>Round3media_Postmark_Helper</class>
|
| 30 |
-
</postmark>
|
| 31 |
-
</helpers>
|
| 32 |
-
</global>
|
| 33 |
-
<adminhtml>
|
| 34 |
-
<translate>
|
| 35 |
-
<modules>
|
| 36 |
-
<Round3media_Postmark>
|
| 37 |
-
<files>
|
| 38 |
-
<default>Round3media_Postmark.csv</default>
|
| 39 |
-
</files>
|
| 40 |
-
</Round3media_Postmark>
|
| 41 |
-
</modules>
|
| 42 |
-
</translate>
|
| 43 |
-
<acl>
|
| 44 |
-
<resources>
|
| 45 |
-
<admin>
|
| 46 |
-
<children>
|
| 47 |
-
<system>
|
| 48 |
-
<children>
|
| 49 |
-
<config>
|
| 50 |
-
<children>
|
| 51 |
-
<postmark>
|
| 52 |
-
<title>Postmark Settings</title>
|
| 53 |
-
</postmark>
|
| 54 |
-
</children>
|
| 55 |
-
</config>
|
| 56 |
-
</children>
|
| 57 |
-
</system>
|
| 58 |
-
</children>
|
| 59 |
-
</admin>
|
| 60 |
-
</resources>
|
| 61 |
-
</acl>
|
| 62 |
-
</adminhtml>
|
| 63 |
-
|
| 64 |
-
<default>
|
| 65 |
-
<postmark>
|
| 66 |
-
<settings>
|
| 67 |
-
<enabled>0</enabled>
|
| 68 |
-
<apikey></apikey>
|
| 69 |
-
<email></email>
|
| 70 |
-
</settings>
|
| 71 |
-
</postmark>
|
| 72 |
-
</default>
|
| 73 |
-
</config>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/Round3media/Postmark/etc/system.xml
DELETED
|
@@ -1,59 +0,0 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
<!-- /** * round3media * * NOTICE OF LICENSE * * This source file is subject
|
| 3 |
-
to the Open Software License (OSL 3.0) * that is bundled with this package
|
| 4 |
-
in the file LICENSE.txt. * It is also available through the world-wide-web
|
| 5 |
-
at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not
|
| 6 |
-
receive a copy of the license and are unable to * obtain it through the world-wide-web,
|
| 7 |
-
please send an email * to info@round3media.com so we can send you a copy
|
| 8 |
-
immediately. * * @category Round3media * @package Round3media_Postmark *
|
| 9 |
-
@copyright Copyright (c) 2009 round3media, LLC * @notice The Postmark logo
|
| 10 |
-
and name are trademarks of Wildbit, LLC * @license http://www.opensource.org/licenses/osl-3.0.php
|
| 11 |
-
Open Software License (OSL 3.0) */ -->
|
| 12 |
-
<config>
|
| 13 |
-
<tabs>
|
| 14 |
-
<postmarkTab1 translate="label" module="postmark">
|
| 15 |
-
<label>Postmark</label>
|
| 16 |
-
<sort_order>220</sort_order>
|
| 17 |
-
</postmarkTab1>
|
| 18 |
-
</tabs>
|
| 19 |
-
<sections>
|
| 20 |
-
<postmark translate="label" module="postmark">
|
| 21 |
-
<label>Postmark Settings</label>
|
| 22 |
-
<tab>postmarkTab1</tab>
|
| 23 |
-
<frontend_type>text</frontend_type>
|
| 24 |
-
<sort_order>150</sort_order>
|
| 25 |
-
<show_in_default>1</show_in_default>
|
| 26 |
-
<show_in_website>1</show_in_website>
|
| 27 |
-
<show_in_store>0</show_in_store>
|
| 28 |
-
<groups>
|
| 29 |
-
<settings translate="label">
|
| 30 |
-
<label>Settings</label>
|
| 31 |
-
<frontend_type>text</frontend_type>
|
| 32 |
-
<sort_order>1</sort_order>
|
| 33 |
-
<show_in_default>1</show_in_default>
|
| 34 |
-
<show_in_website>1</show_in_website>
|
| 35 |
-
<show_in_store>0</show_in_store>
|
| 36 |
-
<fields>
|
| 37 |
-
<enabled translate="label">
|
| 38 |
-
<label>Enable Postmark</label>
|
| 39 |
-
<frontend_type>select</frontend_type>
|
| 40 |
-
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 41 |
-
<sort_order>1</sort_order>
|
| 42 |
-
<show_in_default>1</show_in_default>
|
| 43 |
-
<show_in_website>1</show_in_website>
|
| 44 |
-
<show_in_store>0</show_in_store>
|
| 45 |
-
</enabled>
|
| 46 |
-
<apikey translate="label">
|
| 47 |
-
<label>API Key</label>
|
| 48 |
-
<frontend_type>text</frontend_type>
|
| 49 |
-
<sort_order>5</sort_order>
|
| 50 |
-
<show_in_default>1</show_in_default>
|
| 51 |
-
<show_in_website>1</show_in_website>
|
| 52 |
-
<show_in_store>0</show_in_store>
|
| 53 |
-
</apikey>
|
| 54 |
-
</fields>
|
| 55 |
-
</settings>
|
| 56 |
-
</groups>
|
| 57 |
-
</postmark>
|
| 58 |
-
</sections>
|
| 59 |
-
</config>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/code/community/SUMOHeavy/Postmark/Helper/Data.php
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Postmark integration
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to info@sumoheavy.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category SUMOHeavy
|
| 16 |
+
* @package SUMOHeavy_Postmark
|
| 17 |
+
* @copyright Copyright (c) 2012 SUMO Heavy Industries, LLC
|
| 18 |
+
* @notice The Postmark logo and name are trademarks of Wildbit, LLC
|
| 19 |
+
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
+
*/
|
| 21 |
+
class SUMOHeavy_Postmark_Helper_Data extends Mage_Core_Helper_Abstract
|
| 22 |
+
{
|
| 23 |
+
|
| 24 |
+
}
|
app/code/community/SUMOHeavy/Postmark/Model/Core/Email/Template.php
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Postmark integration
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to info@sumoheavy.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category SUMOHeavy
|
| 16 |
+
* @package SUMOHeavy_Postmark
|
| 17 |
+
* @copyright Copyright (c) 2012 SUMO Heavy Industries, LLC
|
| 18 |
+
* @notice The Postmark logo and name are trademarks of Wildbit, LLC
|
| 19 |
+
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
+
*/
|
| 21 |
+
class SUMOHeavy_Postmark_Model_Core_Email_Template extends Mage_Core_Model_Email_Template
|
| 22 |
+
{
|
| 23 |
+
/**
|
| 24 |
+
* Send mail to recipient
|
| 25 |
+
*
|
| 26 |
+
* @param array|string $email E-mail(s)
|
| 27 |
+
* @param array|string|null $name receiver name(s)
|
| 28 |
+
* @param array $variables template variables
|
| 29 |
+
* @return boolean
|
| 30 |
+
**/
|
| 31 |
+
public function send($email, $name = null, array $variables = array())
|
| 32 |
+
{
|
| 33 |
+
if(!Mage::getStoreConfig('postmark/settings/enabled') || !Mage::getStoreConfig('postmark/settings/apikey')) {
|
| 34 |
+
return parent::send($email, $name, $variables);
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if (!$this->isValidForSend()) {
|
| 38 |
+
Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
|
| 39 |
+
return false;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
if (is_null($name)) {
|
| 43 |
+
$name = substr($email, 0, strpos($email, '@'));
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
$emails = array_values((array)$email);
|
| 47 |
+
$names = is_array($name) ? $name : (array)$name;
|
| 48 |
+
$names = array_values($names);
|
| 49 |
+
foreach ($emails as $key => $email) {
|
| 50 |
+
if (!isset($names[$key])) {
|
| 51 |
+
$names[$key] = substr($email, 0, strpos($email, '@'));
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
$variables['email'] = reset($emails);
|
| 56 |
+
$variables['name'] = reset($names);
|
| 57 |
+
|
| 58 |
+
$mail = $this->getMail();
|
| 59 |
+
|
| 60 |
+
$mailTransport = new SUMOHeavy_Mail_Transport_Postmark(Mage::getStoreConfig('postmark/settings/apikey'));
|
| 61 |
+
Zend_Mail::setDefaultTransport($mailTransport);
|
| 62 |
+
|
| 63 |
+
foreach ($emails as $key => $email) {
|
| 64 |
+
$mail->addTo($email, $names[$key]);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
$this->setUseAbsoluteLinks(true);
|
| 68 |
+
$text = $this->getProcessedTemplate($variables, true);
|
| 69 |
+
|
| 70 |
+
if($this->isPlain()) {
|
| 71 |
+
$mail->setBodyText($text);
|
| 72 |
+
} else {
|
| 73 |
+
$mail->setBodyHTML($text);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
$mail->setSubject($this->getProcessedTemplateSubject($variables));
|
| 77 |
+
$mail->setFrom($this->getSenderEmail(), $this->getSenderName());
|
| 78 |
+
|
| 79 |
+
try {
|
| 80 |
+
$mail->send();
|
| 81 |
+
$this->_mail = null;
|
| 82 |
+
} catch (Exception $e) {
|
| 83 |
+
$this->_mail = null;
|
| 84 |
+
Mage::logException($e);
|
| 85 |
+
return false;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
return true;
|
| 89 |
+
}
|
| 90 |
+
}
|
app/code/community/SUMOHeavy/Postmark/etc/config.xml
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<!--
|
| 3 |
+
/**
|
| 4 |
+
* Postmark integration
|
| 5 |
+
*
|
| 6 |
+
* NOTICE OF LICENSE
|
| 7 |
+
*
|
| 8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 10 |
+
* It is also available through the world-wide-web at this URL:
|
| 11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 12 |
+
* If you did not receive a copy of the license and are unable to
|
| 13 |
+
* obtain it through the world-wide-web, please send an email
|
| 14 |
+
* to info@sumoheavy.com so we can send you a copy immediately.
|
| 15 |
+
*
|
| 16 |
+
* @category SUMOHeavy
|
| 17 |
+
* @package SUMOHeavy_Postmark
|
| 18 |
+
* @copyright Copyright (c) 2012 SUMO Heavy Industries, LLC
|
| 19 |
+
* @notice The Postmark logo and name are trademarks of Wildbit, LLC
|
| 20 |
+
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 21 |
+
*/
|
| 22 |
+
-->
|
| 23 |
+
<config>
|
| 24 |
+
<modules>
|
| 25 |
+
<SUMOHeavy_Postmark>
|
| 26 |
+
<version>2.0.0</version>
|
| 27 |
+
</SUMOHeavy_Postmark>
|
| 28 |
+
</modules>
|
| 29 |
+
|
| 30 |
+
<global>
|
| 31 |
+
<models>
|
| 32 |
+
<core>
|
| 33 |
+
<rewrite>
|
| 34 |
+
<email_template>SUMOHeavy_Postmark_Model_Core_Email_Template</email_template>
|
| 35 |
+
</rewrite>
|
| 36 |
+
</core>
|
| 37 |
+
</models>
|
| 38 |
+
|
| 39 |
+
<helpers>
|
| 40 |
+
<postmark>
|
| 41 |
+
<class>SUMOHeavy_Postmark_Helper</class>
|
| 42 |
+
</postmark>
|
| 43 |
+
</helpers>
|
| 44 |
+
</global>
|
| 45 |
+
|
| 46 |
+
<adminhtml>
|
| 47 |
+
<acl>
|
| 48 |
+
<resources>
|
| 49 |
+
<admin>
|
| 50 |
+
<children>
|
| 51 |
+
<system>
|
| 52 |
+
<children>
|
| 53 |
+
<config>
|
| 54 |
+
<children>
|
| 55 |
+
<postmark>
|
| 56 |
+
<title>Postmark Section</title>
|
| 57 |
+
</postmark>
|
| 58 |
+
</children>
|
| 59 |
+
</config>
|
| 60 |
+
</children>
|
| 61 |
+
</system>
|
| 62 |
+
</children>
|
| 63 |
+
</admin>
|
| 64 |
+
</resources>
|
| 65 |
+
</acl>
|
| 66 |
+
</adminhtml>
|
| 67 |
+
|
| 68 |
+
<default>
|
| 69 |
+
<postmark>
|
| 70 |
+
<settings>
|
| 71 |
+
<enabled>0</enabled>
|
| 72 |
+
</settings>
|
| 73 |
+
</postmark>
|
| 74 |
+
</default>
|
| 75 |
+
</config>
|
app/code/community/SUMOHeavy/Postmark/etc/system.xml
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<!--
|
| 3 |
+
/**
|
| 4 |
+
* Postmark integration
|
| 5 |
+
*
|
| 6 |
+
* NOTICE OF LICENSE
|
| 7 |
+
*
|
| 8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 10 |
+
* It is also available through the world-wide-web at this URL:
|
| 11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 12 |
+
* If you did not receive a copy of the license and are unable to
|
| 13 |
+
* obtain it through the world-wide-web, please send an email
|
| 14 |
+
* to info@sumoheavy.com so we can send you a copy immediately.
|
| 15 |
+
*
|
| 16 |
+
* @category SUMOHeavy
|
| 17 |
+
* @package SUMOHeavy_Postmark
|
| 18 |
+
* @copyright Copyright (c) 2012 SUMO Heavy Industries, LLC
|
| 19 |
+
* @notice The Postmark logo and name are trademarks of Wildbit, LLC
|
| 20 |
+
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 21 |
+
*/
|
| 22 |
+
-->
|
| 23 |
+
<config>
|
| 24 |
+
<sections>
|
| 25 |
+
<postmark translate="label" module="postmark">
|
| 26 |
+
<label>Postmark Integration</label>
|
| 27 |
+
<tab>service</tab>
|
| 28 |
+
<frontend_type>text</frontend_type>
|
| 29 |
+
<sort_order>500</sort_order>
|
| 30 |
+
<show_in_default>1</show_in_default>
|
| 31 |
+
<show_in_website>1</show_in_website>
|
| 32 |
+
<show_in_store>0</show_in_store>
|
| 33 |
+
<groups>
|
| 34 |
+
<settings translate="label">
|
| 35 |
+
<label>Settings</label>
|
| 36 |
+
<frontend_type>text</frontend_type>
|
| 37 |
+
<sort_order>1</sort_order>
|
| 38 |
+
<show_in_default>1</show_in_default>
|
| 39 |
+
<show_in_website>1</show_in_website>
|
| 40 |
+
<show_in_store>0</show_in_store>
|
| 41 |
+
<fields>
|
| 42 |
+
<enabled translate="label">
|
| 43 |
+
<label>Enable Postmark</label>
|
| 44 |
+
<frontend_type>select</frontend_type>
|
| 45 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 46 |
+
<sort_order>1</sort_order>
|
| 47 |
+
<show_in_default>1</show_in_default>
|
| 48 |
+
<show_in_website>1</show_in_website>
|
| 49 |
+
<show_in_store>0</show_in_store>
|
| 50 |
+
</enabled>
|
| 51 |
+
<apikey translate="label">
|
| 52 |
+
<label>API Key</label>
|
| 53 |
+
<frontend_type>text</frontend_type>
|
| 54 |
+
<sort_order>5</sort_order>
|
| 55 |
+
<show_in_default>1</show_in_default>
|
| 56 |
+
<show_in_website>1</show_in_website>
|
| 57 |
+
<show_in_store>0</show_in_store>
|
| 58 |
+
</apikey>
|
| 59 |
+
</fields>
|
| 60 |
+
</settings>
|
| 61 |
+
</groups>
|
| 62 |
+
</postmark>
|
| 63 |
+
</sections>
|
| 64 |
+
</config>
|
app/etc/modules/{Round3media_Postmark.xml → SUMOHeavy_Postmark.xml}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
<!--
|
| 3 |
/**
|
| 4 |
-
*
|
| 5 |
*
|
| 6 |
* NOTICE OF LICENSE
|
| 7 |
*
|
|
@@ -11,19 +11,20 @@
|
|
| 11 |
* http://opensource.org/licenses/osl-3.0.php
|
| 12 |
* If you did not receive a copy of the license and are unable to
|
| 13 |
* obtain it through the world-wide-web, please send an email
|
| 14 |
-
* to info@
|
| 15 |
*
|
| 16 |
-
* @category
|
| 17 |
-
* @package
|
| 18 |
-
* @copyright Copyright (c)
|
|
|
|
| 19 |
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
*/
|
| 21 |
-->
|
| 22 |
<config>
|
| 23 |
<modules>
|
| 24 |
-
<
|
| 25 |
<active>true</active>
|
| 26 |
<codePool>community</codePool>
|
| 27 |
-
</
|
| 28 |
</modules>
|
| 29 |
-
</config>
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
<!--
|
| 3 |
/**
|
| 4 |
+
* Postmark integration
|
| 5 |
*
|
| 6 |
* NOTICE OF LICENSE
|
| 7 |
*
|
| 11 |
* http://opensource.org/licenses/osl-3.0.php
|
| 12 |
* If you did not receive a copy of the license and are unable to
|
| 13 |
* obtain it through the world-wide-web, please send an email
|
| 14 |
+
* to info@sumoheavy.com so we can send you a copy immediately.
|
| 15 |
*
|
| 16 |
+
* @category SUMOHeavy
|
| 17 |
+
* @package SUMOHeavy_Postmark
|
| 18 |
+
* @copyright Copyright (c) 2012 SUMO Heavy Industries, LLC
|
| 19 |
+
* @notice The Postmark logo and name are trademarks of Wildbit, LLC
|
| 20 |
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 21 |
*/
|
| 22 |
-->
|
| 23 |
<config>
|
| 24 |
<modules>
|
| 25 |
+
<SUMOHeavy_Postmark>
|
| 26 |
<active>true</active>
|
| 27 |
<codePool>community</codePool>
|
| 28 |
+
</SUMOHeavy_Postmark>
|
| 29 |
</modules>
|
| 30 |
+
</config>
|
lib/SUMOHeavy/Mail/Transport/Postmark.php
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Postmark integration
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to info@sumoheavy.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category SUMOHeavy
|
| 16 |
+
* @package SUMOHeavy_Postmark
|
| 17 |
+
* @copyright Copyright (c) 2012 SUMO Heavy Industries, LLC
|
| 18 |
+
* @notice The Postmark logo and name are trademarks of Wildbit, LLC
|
| 19 |
+
* @license http://www.opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
+
*/
|
| 21 |
+
class SUMOHeavy_Mail_Transport_Postmark extends Zend_Mail_Transport_Abstract
|
| 22 |
+
{
|
| 23 |
+
/**
|
| 24 |
+
* Postmark API Uri
|
| 25 |
+
*/
|
| 26 |
+
const API_URI = 'https://api.postmarkapp.com/';
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Limit of recipients per message in total.
|
| 30 |
+
*/
|
| 31 |
+
const RECIPIENTS_LIMIT = 20;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Postmark API key
|
| 35 |
+
*
|
| 36 |
+
* @var string
|
| 37 |
+
*/
|
| 38 |
+
protected $_apiKey = null;
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* HTTP client instance
|
| 42 |
+
*
|
| 43 |
+
* @var Zend_Http_Client
|
| 44 |
+
*/
|
| 45 |
+
protected $_client = null;
|
| 46 |
+
|
| 47 |
+
public function __construct($apiKey = '')
|
| 48 |
+
{
|
| 49 |
+
if (empty($apiKey)) {
|
| 50 |
+
throw new Exception( __CLASS__ . ' requires API key' );
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
$this->_apiKey = $apiKey;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Send request to Postmark service
|
| 58 |
+
*
|
| 59 |
+
* @link http://developer.postmarkapp.com/developer-build.html
|
| 60 |
+
* @return stdClass
|
| 61 |
+
*/
|
| 62 |
+
public function _sendMail()
|
| 63 |
+
{
|
| 64 |
+
$data = array(
|
| 65 |
+
'From' => $this->getFrom(),
|
| 66 |
+
'To' => $this->getTo(),
|
| 67 |
+
'Cc' => $this->getCc(),
|
| 68 |
+
'Bcc' => $this->getBcc(),
|
| 69 |
+
'Subject' => $this->getSubject(),
|
| 70 |
+
'ReplyTo' => $this->getReplyTo(),
|
| 71 |
+
'HtmlBody' => $this->getBodyHtml(),
|
| 72 |
+
'TextBody' => $this->getBodyText(),
|
| 73 |
+
'tag' => $this->getTags(),
|
| 74 |
+
'Attachments' => $this->getAttachments(),
|
| 75 |
+
);
|
| 76 |
+
|
| 77 |
+
$response = $this->prepareHttpClient('/email')
|
| 78 |
+
->setMethod(Zend_Http_Client::POST)
|
| 79 |
+
->setRawData(Zend_Json::encode($data))
|
| 80 |
+
->request();
|
| 81 |
+
|
| 82 |
+
return $this->_parseResponse($response);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* Get a http client instance
|
| 87 |
+
*
|
| 88 |
+
* @param string $path
|
| 89 |
+
* @return Zend_Http_Client
|
| 90 |
+
*/
|
| 91 |
+
protected function prepareHttpClient($path)
|
| 92 |
+
{
|
| 93 |
+
return $this->getHttpClient()->setUri(self::API_URI . $path);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Returns http client object
|
| 98 |
+
*
|
| 99 |
+
* @return Zend_Http_Client
|
| 100 |
+
*/
|
| 101 |
+
public function getHttpClient()
|
| 102 |
+
{
|
| 103 |
+
if (null === $this->_client) {
|
| 104 |
+
$this->_client = new Zend_Http_Client();
|
| 105 |
+
|
| 106 |
+
$headers = array(
|
| 107 |
+
'Accept' => 'application/json',
|
| 108 |
+
'X-Postmark-Server-Token' => $this->_apiKey,
|
| 109 |
+
);
|
| 110 |
+
$this->_client->setMethod(Zend_Http_Client::GET)
|
| 111 |
+
->setHeaders($headers);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
return $this->_client;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* Parse response object and check for errors
|
| 119 |
+
*
|
| 120 |
+
* @param Zend_Http_Response $response
|
| 121 |
+
* @return stdClass
|
| 122 |
+
*/
|
| 123 |
+
protected function _parseResponse(Zend_Http_Response $response)
|
| 124 |
+
{
|
| 125 |
+
if ($response->isError()) {
|
| 126 |
+
switch ($response->getStatus()) {
|
| 127 |
+
case 401:
|
| 128 |
+
throw new RuntimeException('Postmark request error: Unauthorized - Missing or incorrect API Key header.');
|
| 129 |
+
break;
|
| 130 |
+
case 422:
|
| 131 |
+
$error = Zend_Json::decode($response->getBody());
|
| 132 |
+
throw new RuntimeException(sprintf('Postmark request error: Unprocessable Entity - API error code %s, message: %s', $error->ErrorCode, $error->Message));
|
| 133 |
+
break;
|
| 134 |
+
case 500:
|
| 135 |
+
throw new RuntimeException('Postmark request error: Postmark Internal Server Error');
|
| 136 |
+
break;
|
| 137 |
+
default:
|
| 138 |
+
throw new RuntimeException('Unknown error during request to Postmark server');
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
return Zend_Json::decode($response->getBody());
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/**
|
| 146 |
+
* Get mail From
|
| 147 |
+
*
|
| 148 |
+
* @return string
|
| 149 |
+
*/
|
| 150 |
+
public function getFrom()
|
| 151 |
+
{
|
| 152 |
+
$headers = $this->_mail->getHeaders();
|
| 153 |
+
$from = array();
|
| 154 |
+
|
| 155 |
+
if (isset($headers['From'])) {
|
| 156 |
+
foreach($headers['From'] as $key => $val) {
|
| 157 |
+
if(empty($key) || $key != 'append') {
|
| 158 |
+
$from[] = $val;
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
return implode(',', $from);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/**
|
| 166 |
+
* Get mail To
|
| 167 |
+
*
|
| 168 |
+
* @return string
|
| 169 |
+
*/
|
| 170 |
+
public function getTo()
|
| 171 |
+
{
|
| 172 |
+
$headers = $this->_mail->getHeaders();
|
| 173 |
+
$to = array();
|
| 174 |
+
|
| 175 |
+
if (isset($headers['To'])) {
|
| 176 |
+
foreach($headers['To'] as $key => $val) {
|
| 177 |
+
if(empty($key) || $key != 'append') {
|
| 178 |
+
$to[] = $val;
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
return implode(',', $to);
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/**
|
| 186 |
+
* Get mail Cc
|
| 187 |
+
*
|
| 188 |
+
* @return string
|
| 189 |
+
*/
|
| 190 |
+
public function getCc()
|
| 191 |
+
{
|
| 192 |
+
$headers = $this->_mail->getHeaders();
|
| 193 |
+
$cc = array();
|
| 194 |
+
|
| 195 |
+
if (isset($headers['Cc'])) {
|
| 196 |
+
foreach($headers['Cc'] as $key => $val) {
|
| 197 |
+
if(empty($key) || $key != 'append') {
|
| 198 |
+
$cc[] = $val;
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
if (count($cc) > self::RECIPIENTS_LIMIT) {
|
| 204 |
+
throw new RuntimeException('Exceeded Postmark Cc recipients limit per message');
|
| 205 |
+
}
|
| 206 |
+
return implode(',', $cc);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
/**
|
| 210 |
+
* Get mail Bcc
|
| 211 |
+
*
|
| 212 |
+
* @return string
|
| 213 |
+
*/
|
| 214 |
+
public function getBcc()
|
| 215 |
+
{
|
| 216 |
+
$headers = $this->_mail->getHeaders();
|
| 217 |
+
$bcc = array();
|
| 218 |
+
|
| 219 |
+
if (isset($headers['Bcc'])) {
|
| 220 |
+
foreach($headers['Bcc'] as $key => $val) {
|
| 221 |
+
if(empty($key) || $key != 'append') {
|
| 222 |
+
$bcc[] = $val;
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
if (count($bcc) > self::RECIPIENTS_LIMIT) {
|
| 227 |
+
throw new RuntimeException('Exceeded Postmark Bcc recipients limit per message');
|
| 228 |
+
}
|
| 229 |
+
return implode(',', $bcc);
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
/**
|
| 233 |
+
* Get mail Reply To
|
| 234 |
+
*
|
| 235 |
+
* @return string
|
| 236 |
+
*/
|
| 237 |
+
public function getReplyTo()
|
| 238 |
+
{
|
| 239 |
+
$headers = $this->_mail->getHeaders();
|
| 240 |
+
$replyTo = array();
|
| 241 |
+
|
| 242 |
+
if (isset($headers['Reply-To'])) {
|
| 243 |
+
foreach($headers['Reply-To'] as $key => $val) {
|
| 244 |
+
if(empty($key) || $key != 'append') {
|
| 245 |
+
$replyTo[] = $val;
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
return implode(',', $replyTo);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
/**
|
| 253 |
+
* Get mail subject
|
| 254 |
+
*
|
| 255 |
+
* @return string
|
| 256 |
+
*/
|
| 257 |
+
public function getSubject()
|
| 258 |
+
{
|
| 259 |
+
if(function_exists('imap_utf8')) {
|
| 260 |
+
return imap_utf8($this->_mail->getSubject());
|
| 261 |
+
}
|
| 262 |
+
return $this->_mail->getSubject();
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
/**
|
| 266 |
+
* Get mail body - html
|
| 267 |
+
*
|
| 268 |
+
* @return string
|
| 269 |
+
*/
|
| 270 |
+
public function getBodyHtml()
|
| 271 |
+
{
|
| 272 |
+
if ($this->_mail->getBodyHtml()) {
|
| 273 |
+
$part = $this->_mail->getBodyHtml();
|
| 274 |
+
$part->encoding = false;
|
| 275 |
+
return $part->getContent();
|
| 276 |
+
}
|
| 277 |
+
return '';
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
/**
|
| 281 |
+
* Get mail body - plain
|
| 282 |
+
*
|
| 283 |
+
* @return string
|
| 284 |
+
*/
|
| 285 |
+
public function getBodyText()
|
| 286 |
+
{
|
| 287 |
+
if ($this->_mail->getBodyText()) {
|
| 288 |
+
$part = $this->_mail->getBodyText();
|
| 289 |
+
$part->encoding = false;
|
| 290 |
+
return $part->getContent();
|
| 291 |
+
}
|
| 292 |
+
return '';
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
/**
|
| 296 |
+
* Get mail Tag
|
| 297 |
+
*
|
| 298 |
+
* @return string
|
| 299 |
+
*/
|
| 300 |
+
public function getTags()
|
| 301 |
+
{
|
| 302 |
+
$headers = $this->_mail->getHeaders();
|
| 303 |
+
$tags = array();
|
| 304 |
+
|
| 305 |
+
if (isset($headers['postmark-tag'])) {
|
| 306 |
+
foreach($headers['postmark-tag'] as $key => $val) {
|
| 307 |
+
if(empty($key) || $key != 'append') {
|
| 308 |
+
$tags[] = $val;
|
| 309 |
+
}
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
return implode(',', $tags);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
/**
|
| 316 |
+
* Get mail Attachments
|
| 317 |
+
*
|
| 318 |
+
* @return array
|
| 319 |
+
*/
|
| 320 |
+
public function getAttachments()
|
| 321 |
+
{
|
| 322 |
+
$attachments = array();
|
| 323 |
+
if($this->_mail->hasAttachments) {
|
| 324 |
+
$parts = $this->_mail->getParts();
|
| 325 |
+
|
| 326 |
+
if(is_array($parts)) {
|
| 327 |
+
$i = 0;
|
| 328 |
+
foreach($parts as $part) {
|
| 329 |
+
$attachments[$i] = array(
|
| 330 |
+
'ContentType' => $part->type,
|
| 331 |
+
'Name' => $part->filename,
|
| 332 |
+
'Content' => $part->getContent(),
|
| 333 |
+
);
|
| 334 |
+
$i++;
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
return $attachments;
|
| 340 |
+
}
|
| 341 |
+
}
|
package.xml
CHANGED
|
@@ -1,20 +1,24 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Round3media_Postmark</name>
|
| 4 |
-
<version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
-
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
-
<summary>Postmark
|
| 10 |
-
<description
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
<compatible/>
|
| 19 |
-
<dependencies
|
| 20 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Round3media_Postmark</name>
|
| 4 |
+
<version>2.0.0</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
+
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL 3.0</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
+
<summary>Send emails through Postmark (http://postmarkapp.com)</summary>
|
| 10 |
+
<description><h2>Postmark Integration</h2>
|
| 11 |
+
<p>You can now send emails from Magento through Postmark, which "helps deliver and track transactional emails for web applications". For more info on Postmark, visit <a href="http://postmarkapp.com">postmarkapp.com</a> The Postmark logo and name are trademarks of <a href="http://wildbit.com">Wildbit, LLC.</a></p></description>
|
| 12 |
+
<notes><ol>
|
| 13 |
+
<li>One of our owners was a partner in Round3Media, this is an update released by SUMO Heavy Industries</li>
|
| 14 |
+
<li>Now supports Bcc</li>
|
| 15 |
+
<li>Refactored code, better documentation</li>
|
| 16 |
+
<li>Moved the main Postmark class to /lib (ZF)</li>
|
| 17 |
+
</ol></notes>
|
| 18 |
+
<authors><author><name>Robert Brodie</name><user>bobbrodie</user><email>robert@sumoheavy.com</email></author></authors>
|
| 19 |
+
<date>2012-07-23</date>
|
| 20 |
+
<time>22:51:57</time>
|
| 21 |
+
<contents><target name="magecommunity"><dir name="SUMOHeavy"><dir name="Postmark"><dir><dir name="Helper"><file name="Data.php" hash="dde66f70d6a0a39b73b40dda01fc7b0a"/></dir><dir name="Model"><dir name="Core"><dir name="Email"><file name="Template.php" hash="77e982707d651f978ef760b3956154c6"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="2102bf2217b526dbfbc10c7988f2646d"/><file name="system.xml" hash="dc19d9c7acdbb69021060e6f8be93aff"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SUMOHeavy_Postmark.xml" hash="3cbd55fce1c474f2ccff0ca0845bef21"/></dir></target><target name="magelib"><dir name="SUMOHeavy"><dir name="Mail"><dir name="Transport"><file name="Postmark.php" hash="076b7c86e688402adcdfefcc7622ead5"/></dir></dir></dir></target></contents>
|
| 22 |
<compatible/>
|
| 23 |
+
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
| 24 |
</package>
|
