Commit 7352aace authored by John Punzalan's avatar John Punzalan

Add Mandrill plugin

parent b148fccf
<?php
/**
*
* @category Ebizmarts
* @package Ebizmarts_Mandrill
* @author Ebizmarts Team <info@ebizmarts.com>
* @license http://opensource.org/licenses/osl-3.0.php
*/
class Ebizmarts_Mandrill_Block_Adminhtml_System_Config_Fieldset_Hint
extends Mage_Adminhtml_Block_Abstract
implements Varien_Data_Form_Element_Renderer_Interface
{
protected $_template = 'ebizmarts/mandrill/system/config/fieldset/hint.phtml';
/**
* Render fieldset html
*
* @param Varien_Data_Form_Element_Abstract $element
* @return string
*/
public function render(Varien_Data_Form_Element_Abstract $element)
{
return $this->toHtml();
}
public function getMandrillVersion()
{
return (string)Mage::getConfig()->getNode('modules/Ebizmarts_Mandrill/version');
}
public function getPxParams()
{
$v = $this->getMandrillVersion();
$ext = "Mandrill;{$v}";
$modulesArray = (array)Mage::getConfig()->getNode('modules')->children();
$aux = (array_key_exists('Enterprise_Enterprise', $modulesArray)) ? 'EE' : 'CE';
$mageVersion = Mage::getVersion();
$mage = "Magento {$aux};{$mageVersion}";
$hash = md5($ext . '_' . $mage . '_' . $ext);
return "ext=$ext&mage={$mage}&ctrl={$hash}";
}
}
\ No newline at end of file
<?php
/**
* Account details renderer for configuration settings
*
* @category Ebizmarts
* @package Ebizmarts_Mandrill
* @author Ebizmarts Team <info@ebizmarts.com>
* @license http://opensource.org/licenses/osl-3.0.php
*/
class Ebizmarts_Mandrill_Block_Adminhtml_System_Config_Userinfo
extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$values = $element->getValues();
$html = '<ul class="checkboxes">';
foreach ($values as $dat) {
$html .= "<li>{$dat['label']}</li>";
}
$html .= '</ul>';
return $html;
}
}
\ No newline at end of file
<?php
/**
* Author : Ebizmarts <info@ebizmarts.com>
* Date : 8/16/14
* Time : 5:18 PM
* File : Templates.php
* Module : magemonkey
*/
class Ebizmarts_Mandrill_Block_Adminhtml_Templates_Templates extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_templates_templates';
$this->_blockGroup = 'ebizmarts_mandrill';
$this->_headerText = Mage::helper('ebizmarts_mandrill')->__('Mandrill Templates');
parent::__construct();
// $this->removeButton('add');
}
public function getGridHtml()
{
return $this->getChildHtml('store_switcher') . $this->getChildHtml('grid');
}
public function getCreateUrl()
{
return $this->getUrl('*/*/new', array('store' => $this->getRequest()->getParam('store', 0)));
}
}
\ No newline at end of file
<?php
/**
* Author : Ebizmarts <info@ebizmarts.com>
* Date : 8/16/14
* Time : 5:21 PM
* File : Grid.php
* Module : magemonkey
*/
class Ebizmarts_Mandrill_Block_Adminhtml_Templates_Templates_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('mandrill_templates');
$this->setUseAjax(false);
$this->setSaveParametersInSession(false);
$this->setPagerVisibility(false);
$this->setFilterVisibility(false);
}
protected function _prepareCollection()
{
// $helper = Mage::helper('ebizmarts_mandrill');
// $mail = $helper->api()->setApiKey($helper->getApiKey());
// $emails = $mail->usersSenders();
$storeId = Mage::app()->getStore()->getId();
$api = new Mandrill_Message(Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::APIKEY, $storeId));
$emails = $api->users->senders();
if ($emails !== FALSE) {
// $_emails = array();
// foreach($emails as $email){
//
// $email = new Varien_Object((array)$email);
// $_emails []= array(
// 'email' => $email->getAddress(),
// 'sent' => $email->getSent(),
// 'rejects' => $email->getRejects(),
// 'complaints' => $email->getComplaints(),
// 'unsubs' => $email->getUnsubs(),
// 'opens' => $email->getUniqueOpens(),
// 'clicks' => $email->getUniqueClicks(),
// 'hard_bounces' => $email->getHardBounces(),
// 'soft_bounces' => $email->getSoftBounces(),
// 'created_at' => $email->getCreatedAt(),
// );
// }
$collection = Mage::getModel('ebizmarts_mandrill/customcollection', array($emails));
} else {
$collection = Mage::getModel('ebizmarts_mandrill/customcollection', array(array()));
}
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn(
'email', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('Email Address'),
'index' => 'address',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'sent', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of messages sent'),
'index' => 'sent',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'rejects', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of rejected messages'),
'index' => 'rejects',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'complaints', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of spam complaints'),
'index' => 'complaints',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'unsubs', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of unsubscribe requests'),
'index' => 'unsubs',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'opens', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of unique opens'),
'index' => 'opens',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'clicks', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of times unique tracked URLs have been clicked'),
'index' => 'clicks',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'hard_bounces', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of hard bounces'),
'index' => 'hard_bounces',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'soft_bounces', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of soft bounces'),
'index' => 'soft_bounces',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'created_at', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('Created At'),
'index' => 'created_at',
'filter' => false,
'sortable' => false
)
);
return parent::_prepareColumns();
}
public function getRowUrl($row)
{
return false;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current' => true));
}
}
\ No newline at end of file
<?php
/**
* Transactional email Mandrill grid container
*
* @category Ebizmarts
* @package Ebizmarts_Mandrill
* @author Ebizmarts Team <info@ebizmarts.com>
* @license http://opensource.org/licenses/osl-3.0.php
*/
class Ebizmarts_Mandrill_Block_Adminhtml_Users_Senders extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_users_senders';
$this->_blockGroup = 'ebizmarts_mandrill';
$this->_headerText = Mage::helper('ebizmarts_mandrill')->__('Verified Email Addresses (%s)', "the senders that have tried to use this account, both verified and unverified.");
parent::__construct();
$this->removeButton('add');
}
public function getGridHtml()
{
return $this->getChildHtml('store_switcher') . $this->getChildHtml('grid');
}
public function getCreateUrl()
{
return $this->getUrl('*/*/new', array('store' => $this->getRequest()->getParam('store', 0)));
}
}
\ No newline at end of file
<?php
/**
* Transactional email Mandrill grid
*
* @category Ebizmarts
* @package Ebizmarts_Mandrill
* @author Ebizmarts Team <info@ebizmarts.com>
* @license http://opensource.org/licenses/osl-3.0.php
*/
class Ebizmarts_Mandrill_Block_Adminhtml_Users_Senders_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('mandrill_valid_emails');
$this->setUseAjax(false);
$this->setSaveParametersInSession(false);
$this->setPagerVisibility(false);
$this->setFilterVisibility(false);
}
protected function _prepareCollection()
{
// $helper = Mage::helper('ebizmarts_mandrill');
// $mail = $helper->api()->setApiKey($helper->getApiKey());
// $emails = $mail->usersSenders();
$storeId = Mage::app()->getStore()->getId();
$api = new Mandrill_Message(Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::APIKEY, $storeId));
$emails = $api->users->senders();
Mage::log($emails);
if ($emails !== FALSE) {
// $_emails = array();
// foreach($emails as $email){
//
// $email = new Varien_Object((array)$email);
// $_emails []= array(
// 'email' => $email->getAddress(),
// 'sent' => $email->getSent(),
// 'rejects' => $email->getRejects(),
// 'complaints' => $email->getComplaints(),
// 'unsubs' => $email->getUnsubs(),
// 'opens' => $email->getUniqueOpens(),
// 'clicks' => $email->getUniqueClicks(),
// 'hard_bounces' => $email->getHardBounces(),
// 'soft_bounces' => $email->getSoftBounces(),
// 'created_at' => $email->getCreatedAt(),
// );
// }
$collection = Mage::getModel('ebizmarts_mandrill/customcollection', array($emails));
} else {
$collection = Mage::getModel('ebizmarts_mandrill/customcollection', array(array()));
}
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn(
'email', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('Email Address'),
'index' => 'address',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'sent', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of messages sent'),
'index' => 'sent',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'rejects', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of rejected messages'),
'index' => 'rejects',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'complaints', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of spam complaints'),
'index' => 'complaints',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'unsubs', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of unsubscribe requests'),
'index' => 'unsubs',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'opens', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of unique opens'),
'index' => 'opens',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'clicks', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of times unique tracked URLs have been clicked'),
'index' => 'clicks',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'hard_bounces', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of hard bounces'),
'index' => 'hard_bounces',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'soft_bounces', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('# of soft bounces'),
'index' => 'soft_bounces',
'filter' => false,
'sortable' => false
)
);
$this->addColumn(
'created_at', array(
'header' => Mage::helper('ebizmarts_mandrill')->__('Created At'),
'index' => 'created_at',
'filter' => false,
'sortable' => false
)
);
return parent::_prepareColumns();
}
public function getRowUrl($row)
{
return false;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current' => true));
}
}
\ No newline at end of file
<?php
/**
* Main module helper
*
* @category Ebizmarts
* @package Ebizmarts_Mandrill
* @author Ebizmarts Team <info@ebizmarts.com>
* @license http://opensource.org/licenses/osl-3.0.php
*/
class Ebizmarts_Mandrill_Helper_Data extends Mage_Core_Helper_Abstract
{
private $_configPath = 'mandrill/general/';
/**
* Check if Mandrill is enabled
*
* @return bool
*/
public function useTransactionalService()
{
$active = Mage::getStoreConfigFlag($this->_configPath . "active");
$key = $this->getApiKey();
return ($active && (strlen($key)));
}
/**
* Retrieves Mandrill API KEY from Magento's configuration
*
* @return string
*/
public function getApiKey($storeId = null)
{
return Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::APIKEY, $storeId);
}
/**
* Get module User-Agent to use on API requests
*
* @return string
*/
public function getUserAgent()
{
$modules = Mage::getConfig()->getNode('modules')->children();
$modulesArray = (array)$modules;
$aux = (array_key_exists('Enterprise_Enterprise', $modulesArray)) ? 'EE' : 'CE';
$v = (string)Mage::getConfig()->getNode('modules/Ebizmarts_Mandrill/version');
$version = strpos(Mage::getVersion(), '-') ? substr(Mage::getVersion(), 0, strpos(Mage::getVersion(), '-')) : Mage::getVersion();
return (string)'Ebizmarts_Mandrill' . $v . '/Mage' . $aux . $version;
}
/**
* Logging facility
*
* @param mixed $data Message to save to file
* @param string $filename log filename, default is <Monkey.log>
* @return Mage_Core_Model_Log_Adapter
*/
public function log($data, $filename = 'Ebizmarts_Mandrill.log')
{
if (Mage::getStoreConfig($this->_configPath . "enable_log")) {
return Mage::getModel('core/log_adapter', $filename)->log($data);
}
}
}
<?php
/**
* Custom collection class for nondb data
*
* @category Ebizmarts
* @package Ebizmarts_Mandrill
* @author Ebizmarts Team <info@ebizmarts.com>
* @license http://opensource.org/licenses/osl-3.0.php
*/
class Ebizmarts_Mandrill_Model_Customcollection extends Varien_Data_Collection
{
/**
* Contains generic data to load on load() method
*
* @var mixed
*/
protected $_toload = NULL;
/**
* Initialize data to be loaded afterwards
*
* @param array $data
* @return Varien_Data_Collection
*/
public function __construct(array $data)
{
$data = current($data);
if (empty($data)) {
return parent::__construct();
}
$this->_toload = $data;
return parent::__construct();
}
/**
* Load data into object
*
* @param bool $printQuery
* @param bool $logQuery
* @return Ebizmarts_MageMonkey_Model_Custom_Collection
*/
public function load($printQuery = false, $logQuery = false)
{
if ($this->isLoaded() || is_null($this->_toload)) {
return $this;
}
foreach ($this->_toload as $row) {
$item = new Varien_Object;
$item->addData($row);
$this->addItem($item);
}
$this->_setIsLoaded();
return $this;
}
}
\ No newline at end of file
<?php
/**
*
* @category Ebizmarts
* @package magemonkey1922
* @author Ebizmarts Team <info@ebizmarts.com>
* @copyright Ebizmarts (http://ebizmarts.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @date: 2/16/16 12:46 PM
* @file: Queue.php
*/
class Ebizmarts_Mandrill_Model_Email_Queue extends Mage_Core_Model_Email_Queue
{
/**
* Send all messages in a queue via manrill
*
* @return Mage_Core_Model_Email_Queue
*/
public function send()
{
/** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
$collection = Mage::getModel('core/email_queue')->getCollection()
->addOnlyForSendingFilter()
->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN)
->setCurPage(1)
->load();
/** @var $message Mage_Core_Model_Email_Queue */
foreach ($collection as $message) {
if ($message->getId()) {
if ($message->getEntityType() == 'order') {
$order = Mage::getModel('sales/order')->load($message->getEntityId());
$storeId = $order->getStoreId();
if (Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::ENABLE, $storeId)) {
$parameters = new Varien_Object($message->getMessageParameters());
$mailer = $this->getMail($storeId);
$mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
$mailer->setSubject($parameters->getSubject());
if ($parameters->getIsPlain()) {
$mailer->setBodyText($message->getMessageBody());
} else {
$mailer->setBodyHtml($message->getMessageBody());
}
foreach ($message->getRecipients() as $recipient) {
list($email, $name, $type) = $recipient;
switch ($type) {
case self::EMAIL_TYPE_TO:
case self::EMAIL_TYPE_CC:
$mailer->addTo($email, $name);
break;
case self::EMAIL_TYPE_BCC:
$mailer->addBcc($email);
break;
}
}
if ($parameters->getReplyTo() !== null) {
$mailer->setReplyTo($parameters->getReplyTo());
}
if ($parameters->getReturnTo() !== null) {
$mailer->setReturnPath($parameters->getReturnTo());
}
try {
Mage::dispatchEvent(
'fooman_emailattachments_before_send_queue',
array(
'mailer' => $mailer,
'message' => $message,
'mail_transport' => false
)
);
$mailer->send();
} catch (Exception $e) {
Mage::logException($e);
}
unset($mailer);
$message->setProcessedAt(Varien_Date::formatDate(true));
$message->save();
} else {
$this->_sendWithoutMandrill($message);
}
}
}
}
return $this;
}
/**
* @param $storeId
* @return Mandrill_Message|Zend_Mail
*/
public function getMail($storeId)
{
if (!Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::ENABLE, $storeId)) {
return null;
}
Mage::helper('ebizmarts_mandrill')->log("store: $storeId API: " . Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::APIKEY, $storeId));
$this->_mail = new Mandrill_Message(Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::APIKEY, $storeId));
return $this->_mail;
}
protected function _sendWithoutMandrill($message)
{
$parameters = new Varien_Object($message->getMessageParameters());
if ($parameters->getReturnPathEmail() !== null) {
$mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail());
Zend_Mail::setDefaultTransport($mailTransport);
}
$mailer = new Zend_Mail('utf-8');
foreach ($message->getRecipients() as $recipient) {
list($email, $name, $type) = $recipient;
switch ($type) {
case self::EMAIL_TYPE_BCC:
$mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?=');
break;
case self::EMAIL_TYPE_TO:
case self::EMAIL_TYPE_CC:
default:
$mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?=');
break;
}
}
if ($parameters->getIsPlain()) {
$mailer->setBodyText($message->getMessageBody());
} else {
$mailer->setBodyHTML($message->getMessageBody());
}
$mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?=');
$mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
if ($parameters->getReplyTo() !== null) {
$mailer->setReplyTo($parameters->getReplyTo());
}
if ($parameters->getReturnTo() !== null) {
$mailer->setReturnPath($parameters->getReturnTo());
}
try {
$mailer->send();
} catch (Exception $e) {
Mage::logException($e);
}
unset($mailer);
$message->setProcessedAt(Varien_Date::formatDate(true));
$message->save();
}
}
<?php
/**
* Author : Ebizmarts <info@ebizmarts.com>
* Date : 8/7/14
* Time : 4:27 PM
* File : Template.php
* Module : Ebizmarts_Mandrill
*/
class Ebizmarts_Mandrill_Model_Email_Template extends Mage_Core_Model_Email_Template
{
// protected $_bcc = array();
protected $_mail = null;
/**
* @param array|string $email
* @param null $name
* @param array $variables
* @return bool
*/
public function send($email, $name = null, array $variables = array())
{
$storeId = Mage::app()->getStore()->getId();
if (!Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::ENABLE, $storeId)) {
return parent::send($email, $name, $variables);
}
if (!$this->isValidForSend()) {
Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
return false;
}
$emails = array_values((array)$email);
$names = is_array($name) ? $name : (array)$name;
$names = array_values($names);
foreach ($emails as $key => $email) {
if (!isset($names[$key])) {
$names[$key] = substr($email, 0, strpos($email, '@'));
}
}
// Get message
$this->setUseAbsoluteLinks(true);
$variables['email'] = reset($emails);
$variables['name'] = reset($names);
$message = $this->getProcessedTemplate($variables, true);
$subject = $this->getProcessedTemplateSubject($variables);
//$email = array('subject' => $this->getProcessedTemplateSubject($variables), 'to' => array());
$email = array('subject' => $subject, 'to' => array());
$setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
switch ($setReturnPath) {
case 1:
$returnPathEmail = $this->getSenderEmail();
break;
case 2:
$returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
break;
default:
$returnPathEmail = null;
break;
}
$mail = $this->getMail();
$max = count($emails);
for ($i = 0; $i < $max; $i++) {
if (isset($names[$i])) {
$email['to'][] = array(
'email' => $emails[$i],
'name' => $names[$i]
);
} else {
$email['to'][] = array(
'email' => $emails[$i],
'name' => ''
);
}
}
foreach ($mail->getBcc() as $bcc) {
$email['to'][] = array(
'email' => $bcc,
'type' => 'bcc'
);
}
$email['from_name'] = $this->getSenderName();
$email['from_email'] = $this->getSenderEmail();
$emailArray = explode('@', $email['from_email']);
if (count($emailArray) > 1) {
$email = $this->_setEmailData($message, $mail, $email, $emailArray, $storeId);
if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
$emailQueue = $this->getQueue();
$emailQueue->setMessageBody($message);
$emailQueue->setMessageParameters(
array(
'subject' => $subject,
'return_path_email' => $returnPathEmail,
'is_plain' => $this->isPlain(),
'from_email' => $this->getSenderEmail(),
'from_name' => $this->getSenderName()
)
)
->addRecipients($emails, $names, Mage_Core_Model_Email_Queue::EMAIL_TYPE_TO)
->addRecipients($this->_bccEmails, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC);
$emailQueue->addMessageToQueue();
return true;
}
}
try {
$result = $mail->messages->send($email);
} catch (Exception $e) {
Mage::logException($e);
return false;
}
return true;
}
/**
* @return Mandrill_Message|Zend_Mail
*/
public function getMail()
{
$storeId = Mage::app()->getStore()->getId();
if (!Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::ENABLE, $storeId)) {
return parent::getMail();
}
if ($this->_mail) {
return $this->_mail;
} else {
$storeId = Mage::app()->getStore()->getId();
Mage::helper('ebizmarts_mandrill')->log("store: $storeId API: " . Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::APIKEY, $storeId));
$this->_mail = new Mandrill_Message(Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::APIKEY, $storeId));
return $this->_mail;
}
}
protected function _setEmailData($message, $mail, $email, $emailArray, $storeId)
{
$mandrillSenders = $mail->senders->domains();
$senderExists = false;
foreach ($mandrillSenders as $sender) {
if ($emailArray[1] == $sender['domain']) {
$senderExists = true;
}
}
if (!$senderExists) {
$email['from_email'] = Mage::getStoreConfig('trans_email/ident_general/email', $storeId);
}
$headers = $mail->getHeaders();
$headers[] = Mage::helper('ebizmarts_mandrill')->getUserAgent();
$email['headers'] = $headers;
if (isset($variables['tags']) && count($variables['tags'])) {
$email ['tags'] = $variables['tags'];
}
if (isset($variables['tags']) && count($variables['tags'])) {
$email ['tags'] = $variables['tags'];
} else {
$templateId = (string)$this->getId();
$templates = parent::getDefaultTemplates();
if (isset($templates[$templateId]) && isset($templates[$templateId]['label'])) {
$email ['tags'] = array(substr($templates[$templateId]['label'], 0, 50));
} else {
if ($this->getTemplateCode()) {
$email ['tags'] = array(substr($this->getTemplateCode(), 0, 50));
} else {
if ($templateId) {
$email ['tags'] = array(substr($templateId, 0, 50));
} else {
$email['tags'] = array('default_tag');
}
}
}
}
if ($att = $mail->getAttachments()) {
$email['attachments'] = $att;
}
if ($this->isPlain()) {
$email['text'] = $message;
} else {
$email['html'] = $message;
}
return $email;
}
}
\ No newline at end of file
<?php
/**
* Author : Ebizmarts <info@ebizmarts.com>
* Date : 8/6/14
* Time : 1:32 AM
* File : Config.php
* Module : Ebizmarts_Mandrill
*/
class Ebizmarts_Mandrill_Model_System_Config
{
const ENABLE = 'mandrill/general/active';
const APIKEY = 'mandrill/general/apikey';
const ENABLE_LOG = 'mandrill/general/enable_log';
}
\ No newline at end of file
<?php
/**
* Author : Ebizmarts <info@ebizmarts.com>
* Date : 8/6/14
* Time : 12:16 AM
* File : Userinfo.php
* Module : Ebizmarts_Mandrill
*/
class Ebizmarts_Mandrill_Model_System_Config_Source_Userinfo
{
/**
* Account details storage
*
* @access protected
* @var bool|array
*/
protected $_accountDetails = "--- Enter your API KEY first ---";
/**
* Set AccountDetails on class attribute if not already set
*
* @return void
*/
public function __construct()
{
$storeId = Mage::app()->getStore()->getId();
if (Mage::app()->getRequest()->getParam('store')) {
$stores = Mage::app()->getStores();
foreach ($stores as $store) {
if ($store->getCode() == Mage::app()->getRequest()->getParam('store')) {
$storeId = $store->getStoreId();
break;
}
}
}
if ((!is_array($this->_accountDetails) || isset($this->_accountDetails['status'])) && Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::APIKEY, $storeId)) {
$api = new Mandrill_Message(Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::APIKEY, $storeId));
try {
$this->_accountDetails = $api->users->info();
} catch (Exception $e) {
$this->_accountDetails = "--- Invalid API key ---";
}
}
}
/**
* Return data if API key is entered
*
* @return array
*/
public function toOptionArray()
{
$helper = Mage::helper('ebizmarts_mandrill');
if (is_array($this->_accountDetails)) {
if (!isset($this->_accountDetails['status'])) {
return array(
array('value' => 0, 'label' => $helper->__("<strong>Username</strong>: %s %s", $this->_accountDetails["username"], "<small>used for SMTP authentication</small>")),
array('value' => 1, 'label' => $helper->__('<strong>Reputation</strong>: %s %s', $this->_accountDetails['reputation'], "<small>scale from 0 to 100, with 75 generally being a \"good\" reputation</small>")),
array('value' => 2, 'label' => $helper->__('<strong>Hourly Quota</strong>: %s %s', $this->_accountDetails['hourly_quota'], "<small>the maximum number of emails Mandrill will deliver for this user each hour. Any emails beyond that will be accepted and queued for later delivery. Users with higher reputations will have higher hourly quotas</small>")),
array('value' => 3, 'label' => $helper->__('<strong>Backlog</strong>: %s %s', $this->_accountDetails['backlog'], "<small>the number of emails that are queued for delivery due to exceeding your monthly or hourly quotas</small>"))
);
} else {
return array(array('value' => '', 'label' => $helper->__('--- Invalid API KEY ---')));
}
} else {
return array(array('value' => '', 'label' => $helper->__($this->_accountDetails)));
}
}
}
<?php
/**
* Transactional Email Service manager controller
*
* @category Ebizmarts
* @package Ebizmarts_Mandrill
* @author Ebizmarts Team <info@ebizmarts.com>
* @license http://opensource.org/licenses/osl-3.0.php
*/
class Ebizmarts_Mandrill_Adminhtml_Mandrill_UsersController extends Mage_Adminhtml_Controller_Action
{
/**
* Initialize action
*
* @return Mage_Adminhtml_Controller_Action
*/
protected function _initAction()
{
$this->_title($this->__('Mandrill'));
$this->loadLayout();
$this->_setActiveMenu('system');
return $this;
}
/**
* Mandrill verified emails grid
*/
public function sendersAction()
{
$this->_initAction();
$this->_title($this->__('Verified Senders'));
$this->renderLayout();
}
protected function _isAllowed()
{
switch ($this->getRequest()->getActionName()) {
case 'senders':
$acl = 'system/email_template/mandrill/users_senders';
break;
}
return Mage::getSingleton('admin/session')->isAllowed($acl);
}
}
\ No newline at end of file
<?xml version="1.0"?>
<config>
<menu>
<system>
<children>
<email_template>
<children>
<mandrill translate="title" module="ebizmarts_mandrill">
<title>Mandrill</title>
<children>
<users_senders translate="title" module="ebizmarts_mandrill">
<title>Senders</title>
<action>adminhtml/mandrill_users/senders</action>
</users_senders>
</children>
</mandrill>
</children>
</email_template>
</children>
</system>
<newsletter>
<children>
<ebizmarts_mandrill>
<title>Mandrill Settings</title>
<sort_order>999</sort_order>
<action>adminhtml/system_config/edit/section/mandrill</action>
</ebizmarts_mandrill>
</children>
</newsletter>
</menu>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<email_template>
<children>
<mandrill translate="title" module="ebizmarts_mandrill">
<title>Mandrill</title>
<children>
<users_senders translate="title" module="ebizmarts_mandrill">
<title>Senders</title>
<action>adminhtml/mandrill_users/senders</action>
</users_senders>
</children>
</mandrill>
</children>
</email_template>
</children>
</system>
<system>
<children>
<config>
<children>
<mandrill translate="title" module="ebizmarts_mandrill">
<title>Mandrill Configuration</title>
</mandrill>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<config>
<modules>
<Ebizmarts_Mandrill>
<version>2.0.13</version>
</Ebizmarts_Mandrill>
</modules>
<global>
<models>
<ebizmarts_mandrill>
<class>Ebizmarts_Mandrill_Model</class>
<resourceModel>ebizmarts_mandrill_resource</resourceModel>
</ebizmarts_mandrill>
<ebizmarts_mandrill_resource>
<class>Ebizmarts_Mandrill_Model_Resource</class>
</ebizmarts_mandrill_resource>
<core>
<rewrite>
<email_template>Ebizmarts_Mandrill_Model_Email_Template</email_template>
<email_queue>Ebizmarts_Mandrill_Model_Email_Queue</email_queue>
</rewrite>
</core>
</models>
<blocks>
<ebizmarts_mandrill>
<class>Ebizmarts_Mandrill_Block</class>
</ebizmarts_mandrill>
</blocks>
<helpers>
<ebizmarts_mandrill>
<class>Ebizmarts_Mandrill_Helper</class>
</ebizmarts_mandrill>
</helpers>
</global>
<frontend>
<translate>
<modules>
<Ebizmarts_Mandrill>
<files>
<default>Ebizmarts_Mandrill.csv</default>
</files>
</Ebizmarts_Mandrill>
</modules>
</translate>
</frontend>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<mandrill after="Mage_Adminhtml">Ebizmarts_Mandrill_Adminhtml</mandrill>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<mandrill>
<file>ebizmarts/mandrill.xml</file>
</mandrill>
</updates>
</layout>
<translate>
<modules>
<Ebizmarts_Mandrill>
<files>
<default>Ebizmarts_Mandrill.csv</default>
</files>
</Ebizmarts_Mandrill>
</modules>
</translate>
</adminhtml>
<default>
<mandrill>
<general>
<active>0</active>
</general>
</mandrill>
</default>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<config>
<sections>
<mandrill translate="label" module="ebizmarts_mandrill">
<label><![CDATA[Mandrill]]></label>
<class>mandrill-section separator-top</class>
<header_css>mandrill-header</header_css>
<tab>monkey</tab>
<sort_order>200</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<hint>
<frontend_model>ebizmarts_mandrill/adminhtml_system_config_fieldset_hint</frontend_model>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</hint>
<general translate="label comment">
<comment><![CDATA[<a href="http://mandrill.com/signup/?pid=ebizmart&source=website" target="_blank">Get a free Mandrill account now</a>]]></comment>
<label><![CDATA[Mandrill, SMARTER EMAIL FOR APPS integration by ebizmarts]]></label>
<sort_order>10</sort_order>
<frontend_type>text</frontend_type>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</active>
<apikey translate="label comment">
<label>API Key</label>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[Your API Key]]></comment>
<depends>
<active>1</active>
</depends>
</apikey>
<enable_log translate="label comment">
<label>Enable Log</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>1</show_in_store>
<comment>File is {{base_dir}}/var/log/Ebizmarts_Mandrill.log</comment>
<depends>
<active>1</active>
</depends>
</enable_log>
<user_info translate="label comment">
<label>Account Info</label>
<frontend_model>ebizmarts_mandrill/adminhtml_system_config_userinfo</frontend_model>
<source_model>ebizmarts_mandrill/system_config_source_userinfo</source_model>
<sort_order>40</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[]]></comment>
<depends>
<active>1</active>
</depends>
</user_info>
</fields>
</general>
</groups>
</mandrill>
</sections>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<layout>
<adminhtml_system_config_edit>
<reference name="head">
<action method="addCss">
<stylesheet>ebizmarts/mandrill/mandrill.css</stylesheet>
</action>
</reference>
</adminhtml_system_config_edit>
<adminhtml_mandrill_users_senders>
<reference name="content">
<block type="ebizmarts_mandrill/adminhtml_users_senders" name="mc_transactionalemail_mandrill">
<block type="adminhtml/store_switcher" name="store_switcher" as="store_switcher">
<action method="setUseConfirm">
<params>0</params>
</action>
</block>
</block>
</reference>
</adminhtml_mandrill_users_senders>
</layout>
\ No newline at end of file
<div class="mandrill-notice">
<img width="244px" height="60px" src="https://ebizmarts-website.s3.amazonaws.com/Logo_Ebizmarts.png"/>
<h4>
<?php echo $this->__('<strong style="color:#EA7601;">Mandrill v%s by</strong> <a target="_blank" href="http://ebizmarts.com"><strong>ebizmarts</strong></a>', $this->getMandrillVersion()) ?>
<br>
<?php echo $this->__('Need help? See our <a href="http://wiki.ebizmarts.com/installation" target="_blank">Wiki</a> or browse our <a href="http://ebizmarts.com/forums/view/1" target="_blank">support forums</a> Got feedback? <a href="mailto:mailchimp@ebizmarts-desk.zendesk.com?Subject=Mandrill Version %s">Email us</a>', $this->getMandrillVersion()) ?>
</h4>
<h3><a style="padding-top: 5px;padding-bottom:5px;padding-left: 30px;padding-right: 30px;background-color:#D75F07 ;color:white;font-weight: bold" href="http://www.mailchimp.com/signup?pid=ebizmarts&source=website" target="_blank">Support MageMonkey, Subscribe for a free MailChimp Account!</a> </h3>
</div>
\ No newline at end of file
<?xml version="1.0"?>
<config>
<modules>
<Ebizmarts_Mandrill>
<active>true</active>
<codePool>community</codePool>
<depends>
<Mage_Core/>
</depends>
</Ebizmarts_Mandrill>
</modules>
</config>
"Mandrill","Mandrill"
\ No newline at end of file
<?php
if (defined("COMPILER_INCLUDE_PATH")) {
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Templates.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Exports.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Users.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Rejects.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Inbound.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Tags.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Messages.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Whitelists.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Ips.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Internal.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Subaccounts.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Urls.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Webhooks.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Senders.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Metadata.php');
require_once(dirname(__FILE__) . '/Mandrill/Mandrill/Exceptions.php');
} else {
require_once(dirname(__FILE__) . '/Mandrill/Templates.php');
require_once(dirname(__FILE__) . '/Mandrill/Exports.php');
require_once(dirname(__FILE__) . '/Mandrill/Users.php');
require_once(dirname(__FILE__) . '/Mandrill/Rejects.php');
require_once(dirname(__FILE__) . '/Mandrill/Inbound.php');
require_once(dirname(__FILE__) . '/Mandrill/Tags.php');
require_once(dirname(__FILE__) . '/Mandrill/Messages.php');
require_once(dirname(__FILE__) . '/Mandrill/Whitelists.php');
require_once(dirname(__FILE__) . '/Mandrill/Ips.php');
require_once(dirname(__FILE__) . '/Mandrill/Internal.php');
require_once(dirname(__FILE__) . '/Mandrill/Subaccounts.php');
require_once(dirname(__FILE__) . '/Mandrill/Urls.php');
require_once(dirname(__FILE__) . '/Mandrill/Webhooks.php');
require_once(dirname(__FILE__) . '/Mandrill/Senders.php');
require_once(dirname(__FILE__) . '/Mandrill/Metadata.php');
require_once(dirname(__FILE__) . '/Mandrill/Exceptions.php');
}
class Mandrill_Mandrill
{
public $apikey;
public $ch;
public $root = 'https://mandrillapp.com/api/1.0';
public $debug = false;
public static $errorMap = array(
"ValidationError" => "Mandrill_ValidationError",
"Invalid_Key" => "Mandrill_Invalid_Key",
"PaymentRequired" => "Mandrill_PaymentRequired",
"Unknown_Subaccount" => "Mandrill_Unknown_Subaccount",
"Unknown_Template" => "Mandrill_Unknown_Template",
"ServiceUnavailable" => "Mandrill_ServiceUnavailable",
"Unknown_Message" => "Mandrill_Unknown_Message",
"Invalid_Tag_Name" => "Mandrill_Invalid_Tag_Name",
"Invalid_Reject" => "Mandrill_Invalid_Reject",
"Unknown_Sender" => "Mandrill_Unknown_Sender",
"Unknown_Url" => "Mandrill_Unknown_Url",
"Unknown_TrackingDomain" => "Mandrill_Unknown_TrackingDomain",
"Invalid_Template" => "Mandrill_Invalid_Template",
"Unknown_Webhook" => "Mandrill_Unknown_Webhook",
"Unknown_InboundDomain" => "Mandrill_Unknown_InboundDomain",
"Unknown_InboundRoute" => "Mandrill_Unknown_InboundRoute",
"Unknown_Export" => "Mandrill_Unknown_Export",
"IP_ProvisionLimit" => "Mandrill_IP_ProvisionLimit",
"Unknown_Pool" => "Mandrill_Unknown_Pool",
"NoSendingHistory" => "Mandrill_NoSendingHistory",
"PoorReputation" => "Mandrill_PoorReputation",
"Unknown_IP" => "Mandrill_Unknown_IP",
"Invalid_EmptyDefaultPool" => "Mandrill_Invalid_EmptyDefaultPool",
"Invalid_DeleteDefaultPool" => "Mandrill_Invalid_DeleteDefaultPool",
"Invalid_DeleteNonEmptyPool" => "Mandrill_Invalid_DeleteNonEmptyPool",
"Invalid_CustomDNS" => "Mandrill_Invalid_CustomDNS",
"Invalid_CustomDNSPending" => "Mandrill_Invalid_CustomDNSPending",
"Metadata_FieldLimit" => "Mandrill_Metadata_FieldLimit",
"Unknown_MetadataField" => "Mandrill_Unknown_MetadataField"
);
public function __construct($apikey = null)
{
if (!$apikey) $apikey = getenv('MANDRILL_APIKEY');
if (!$apikey) $apikey = $this->readConfigs();
if (!$apikey) throw new Mandrill_Error('You must provide a Mandrill API key');
$this->apikey = $apikey;
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_USERAGENT, 'Mandrill-PHP/1.0.53');
curl_setopt($this->ch, CURLOPT_POST, true);
if (!ini_get('open_basedir')) {
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
}
curl_setopt($this->ch, CURLOPT_HEADER, false);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 600);
$this->root = rtrim($this->root, '/') . '/';
$this->templates = new Mandrill_Templates($this);
$this->exports = new Mandrill_Exports($this);
$this->users = new Mandrill_Users($this);
$this->rejects = new Mandrill_Rejects($this);
$this->inbound = new Mandrill_Inbound($this);
$this->tags = new Mandrill_Tags($this);
$this->messages = new Mandrill_Messages($this);
$this->whitelists = new Mandrill_Whitelists($this);
$this->ips = new Mandrill_Ips($this);
$this->internal = new Mandrill_Internal($this);
$this->subaccounts = new Mandrill_Subaccounts($this);
$this->urls = new Mandrill_Urls($this);
$this->webhooks = new Mandrill_Webhooks($this);
$this->senders = new Mandrill_Senders($this);
$this->metadata = new Mandrill_Metadata($this);
}
public function __destruct()
{
curl_close($this->ch);
}
public function call($url, $params)
{
$params['key'] = $this->apikey;
$params = json_encode($params);
$ch = $this->ch;
curl_setopt($ch, CURLOPT_URL, $this->root . $url . '.json');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_VERBOSE, $this->debug);
$start = microtime(true);
$this->log('Call to ' . $this->root . $url . '.json: ' . $params);
if ($this->debug) {
$curlBuffer = fopen('php://memory', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $curlBuffer);
}
$responseBody = curl_exec($ch);
$info = curl_getinfo($ch);
$time = microtime(true) - $start;
if ($this->debug) {
rewind($curlBuffer);
$this->log(stream_get_contents($curlBuffer));
fclose($curlBuffer);
}
$this->log('Completed in ' . number_format($time * 1000, 2) . 'ms');
$this->log('Got response: ' . $responseBody);
if (curl_error($ch)) {
throw new Mandrill_HttpError("API call to $url failed: " . curl_error($ch));
}
$result = json_decode($responseBody, true);
if ($result === null) throw new Mandrill_Error('We were unable to decode the JSON response from the Mandrill API: ' . $responseBody);
try {
if (floor($info['http_code'] / 100) >= 4) {
throw $this->castError($result);
}
} catch (Exception $e) {
$this->log($e->getMessage());
}
return $result;
}
public function readConfigs()
{
$paths = array('~/.mandrill.key', '/etc/mandrill.key');
foreach ($paths as $path) {
if (file_exists($path)) {
$apikey = trim(file_get_contents($path));
if ($apikey) return $apikey;
}
}
return false;
}
public function castError($result)
{
if ($result['status'] !== 'error' || !$result['name']) throw new Mandrill_Error('We received an unexpected error: ' . json_encode($result));
$class = (isset(self::$errorMap[$result['name']])) ? self::$errorMap[$result['name']] : 'Mandrill_Error';
return new $class($result['message'], $result['code']);
}
public function log($msg)
{
if ($this->debug) error_log($msg);
}
}
<?php
// This is an external library.
// @codingStandardsIgnoreStart
class Mandrill_Error extends Exception
{
}
class Mandrill_HttpError extends Mandrill_Error
{
}
/**
* The parameters passed to the API call are invalid or not provided when required
*/
class Mandrill_ValidationError extends Mandrill_Error
{
}
/**
* The provided API key is not a valid Mandrill API key
*/
class Mandrill_Invalid_Key extends Mandrill_Error
{
}
/**
* The requested feature requires payment.
*/
class Mandrill_PaymentRequired extends Mandrill_Error
{
}
/**
* The provided subaccount id does not exist.
*/
class Mandrill_Unknown_Subaccount extends Mandrill_Error
{
}
/**
* The requested template does not exist
*/
class Mandrill_Unknown_Template extends Mandrill_Error
{
}
/**
* The subsystem providing this API call is down for maintenance
*/
class Mandrill_ServiceUnavailable extends Mandrill_Error
{
}
/**
* The provided message id does not exist.
*/
class Mandrill_Unknown_Message extends Mandrill_Error
{
}
/**
* The requested tag does not exist or contains invalid characters
*/
class Mandrill_Invalid_Tag_Name extends Mandrill_Error
{
}
/**
* The requested email is not in the rejection list
*/
class Mandrill_Invalid_Reject extends Mandrill_Error
{
}
/**
* The requested sender does not exist
*/
class Mandrill_Unknown_Sender extends Mandrill_Error
{
}
/**
* The requested URL has not been seen in a tracked link
*/
class Mandrill_Unknown_Url extends Mandrill_Error
{
}
/**
* The provided tracking domain does not exist.
*/
class Mandrill_Unknown_TrackingDomain extends Mandrill_Error
{
}
/**
* The given template name already exists or contains invalid characters
*/
class Mandrill_Invalid_Template extends Mandrill_Error
{
}
/**
* The requested webhook does not exist
*/
class Mandrill_Unknown_Webhook extends Mandrill_Error
{
}
/**
* The requested inbound domain does not exist
*/
class Mandrill_Unknown_InboundDomain extends Mandrill_Error
{
}
/**
* The provided inbound route does not exist.
*/
class Mandrill_Unknown_InboundRoute extends Mandrill_Error
{
}
/**
* The requested export job does not exist
*/
class Mandrill_Unknown_Export extends Mandrill_Error
{
}
/**
* A dedicated IP cannot be provisioned while another request is pending.
*/
class Mandrill_IP_ProvisionLimit extends Mandrill_Error
{
}
/**
* The provided dedicated IP pool does not exist.
*/
class Mandrill_Unknown_Pool extends Mandrill_Error
{
}
/**
* The user hasn't started sending yet.
*/
class Mandrill_NoSendingHistory extends Mandrill_Error
{
}
/**
* The user's reputation is too low to continue.
*/
class Mandrill_PoorReputation extends Mandrill_Error
{
}
/**
* The provided dedicated IP does not exist.
*/
class Mandrill_Unknown_IP extends Mandrill_Error
{
}
/**
* You cannot remove the last IP from your default IP pool.
*/
class Mandrill_Invalid_EmptyDefaultPool extends Mandrill_Error
{
}
/**
* The default pool cannot be deleted.
*/
class Mandrill_Invalid_DeleteDefaultPool extends Mandrill_Error
{
}
/**
* Non-empty pools cannot be deleted.
*/
class Mandrill_Invalid_DeleteNonEmptyPool extends Mandrill_Error
{
}
/**
* The domain name is not configured for use as the dedicated IP's custom reverse DNS.
*/
class Mandrill_Invalid_CustomDNS extends Mandrill_Error
{
}
/**
* A custom DNS change for this dedicated IP is currently pending.
*/
class Mandrill_Invalid_CustomDNSPending extends Mandrill_Error
{
}
/**
* Custom metadata field limit reached.
*/
class Mandrill_Metadata_FieldLimit extends Mandrill_Error
{
}
/**
* The provided metadata field name does not exist.
*/
class Mandrill_Unknown_MetadataField extends Mandrill_Error
{
}
// @codingStandardsIgnoreEnd
\ No newline at end of file
<?php
class Mandrill_Exports
{
public function __construct(Mandrill_Mandrill $master)
{
$this->master = $master;
}
/**
* Returns information about an export job. If the export job's state is 'complete',
* the returned data will include a URL you can use to fetch the results. Every export
* job produces a zip archive, but the format of the archive is distinct for each job
* type. The api calls that initiate exports include more details about the output format
* for that job type.
* @param string $id an export job identifier
* @return struct the information about the export
* - id string the unique identifier for this Export. Use this identifier when checking the export job's status
* - created_at string the date and time that the export job was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - type string the type of the export job - activity, reject, or whitelist
* - finished_at string the date and time that the export job was finished as a UTC string in YYYY-MM-DD HH:MM:SS format
* - state string the export job's state - waiting, working, complete, error, or expired.
* - result_url string the url for the export job's results, if the job is completed.
*/
public function info($id)
{
$_params = array("id" => $id);
return $this->master->call('exports/info', $_params);
}
/**
* Returns a list of your exports.
* @return array the account's exports
* - return[] struct the individual export info
* - id string the unique identifier for this Export. Use this identifier when checking the export job's status
* - created_at string the date and time that the export job was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - type string the type of the export job - activity, reject, or whitelist
* - finished_at string the date and time that the export job was finished as a UTC string in YYYY-MM-DD HH:MM:SS format
* - state string the export job's state - waiting, working, complete, error, or expired.
* - result_url string the url for the export job's results, if the job is completed.
*/
public function getList()
{
$_params = array();
return $this->master->call('exports/list', $_params);
}
/**
* Begins an export of your rejection blacklist. The blacklist will be exported to a zip archive
* containing a single file named rejects.csv that includes the following fields: email,
* reason, detail, created_at, expires_at, last_event_at, expires_at.
* @param string $notifyEmail an optional email address to notify when the export job has finished.
* @return struct information about the rejects export job that was started
* - id string the unique identifier for this Export. Use this identifier when checking the export job's status
* - created_at string the date and time that the export job was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - type string the type of the export job
* - finished_at string the date and time that the export job was finished as a UTC string in YYYY-MM-DD HH:MM:SS format, or null for jobs that have not run
* - state string the export job's state
* - result_url string the url for the export job's results, if the job is complete
*/
public function rejects($notifyEmail = null)
{
$_params = array("notify_email" => $notifyEmail);
return $this->master->call('exports/rejects', $_params);
}
/**
* Begins an export of your rejection whitelist. The whitelist will be exported to a zip archive
* containing a single file named whitelist.csv that includes the following fields:
* email, detail, created_at.
* @param string $notifyEmail an optional email address to notify when the export job has finished.
* @return struct information about the whitelist export job that was started
* - id string the unique identifier for this Export. Use this identifier when checking the export job's status
* - created_at string the date and time that the export job was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - type string the type of the export job
* - finished_at string the date and time that the export job was finished as a UTC string in YYYY-MM-DD HH:MM:SS format, or null for jobs that have not run
* - state string the export job's state
* - result_url string the url for the export job's results, if the job is complete
*/
public function whitelist($notifyEmail = null)
{
$_params = array("notify_email" => $notifyEmail);
return $this->master->call('exports/whitelist', $_params);
}
/**
* Begins an export of your activity history. The activity will be exported to a zip archive
* containing a single file named activity.csv in the same format as you would be able to export
* from your account's activity view. It includes the following fields: Date, Email Address,
* Sender, Subject, Status, Tags, Opens, Clicks, Bounce Detail. If you have configured any custom
* metadata fields, they will be included in the exported data.
* @param string $notifyEmail an optional email address to notify when the export job has finished
* @param string $dateFrom start date as a UTC string in YYYY-MM-DD HH:MM:SS format
* @param string $dateTo end date as a UTC string in YYYY-MM-DD HH:MM:SS format
* @param array $tags an array of tag names to narrow the export to; will match messages that contain ANY of the tags
* - tags[] string a tag name
* @param array $senders an array of senders to narrow the export to
* - senders[] string a sender address
* @param array $states an array of states to narrow the export to; messages with ANY of the states will be included
* - states[] string a message state
* @param array $apiKeys an array of api keys to narrow the export to; messsagse sent with ANY of the keys will be included
* - api_keys[] string an API key associated with your account
* @return struct information about the activity export job that was started
* - id string the unique identifier for this Export. Use this identifier when checking the export job's status
* - created_at string the date and time that the export job was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - type string the type of the export job
* - finished_at string the date and time that the export job was finished as a UTC string in YYYY-MM-DD HH:MM:SS format, or null for jobs that have not run
* - state string the export job's state
* - result_url string the url for the export job's results, if the job is complete
*/
public function activity($notifyEmail = null, $dateFrom = null, $dateTo = null, $tags = null, $senders = null, $states = null, $apiKeys = null)
{
$_params = array("notify_email" => $notifyEmail, "date_from" => $dateFrom, "date_to" => $dateTo, "tags" => $tags, "senders" => $senders, "states" => $states, "api_keys" => $apiKeys);
return $this->master->call('exports/activity', $_params);
}
}
<?php
class Mandrill_HttpError extends Mandrill_Error
{
}
\ No newline at end of file
<?php
class Mandrill_Inbound
{
public function __construct(Mandrill_Mandrill $master)
{
$this->master = $master;
}
/**
* List the domains that have been configured for inbound delivery
* @return array the inbound domains associated with the account
* - return[] struct the individual domain info
* - domain string the domain name that is accepting mail
* - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
* - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
*/
public function domains()
{
$_params = array();
return $this->master->call('inbound/domains', $_params);
}
/**
* Add an inbound domain to your account
* @param string $domain a domain name
* @return struct information about the domain
* - domain string the domain name that is accepting mail
* - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
* - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
*/
public function addDomain($domain)
{
$_params = array("domain" => $domain);
return $this->master->call('inbound/add-domain', $_params);
}
/**
* Check the MX settings for an inbound domain. The domain must have already been added with the add-domain call
* @param string $domain an existing inbound domain
* @return struct information about the inbound domain
* - domain string the domain name that is accepting mail
* - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
* - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
*/
public function checkDomain($domain)
{
$_params = array("domain" => $domain);
return $this->master->call('inbound/check-domain', $_params);
}
/**
* Delete an inbound domain from the account. All mail will stop routing for this domain immediately.
* @param string $domain an existing inbound domain
* @return struct information about the deleted domain
* - domain string the domain name that is accepting mail
* - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
* - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
*/
public function deleteDomain($domain)
{
$_params = array("domain" => $domain);
return $this->master->call('inbound/delete-domain', $_params);
}
/**
* List the mailbox routes defined for an inbound domain
* @param string $domain the domain to check
* @return array the routes associated with the domain
* - return[] struct the individual mailbox route
* - id string the unique identifier of the route
* - pattern string the search pattern that the mailbox name should match
* - url string the webhook URL where inbound messages will be published
*/
public function routes($domain)
{
$_params = array("domain" => $domain);
return $this->master->call('inbound/routes', $_params);
}
/**
* Add a new mailbox route to an inbound domain
* @param string $domain an existing inbound domain
* @param string $pattern the search pattern that the mailbox name should match
* @param string $url the webhook URL where the inbound messages will be published
* @return struct the added mailbox route information
* - id string the unique identifier of the route
* - pattern string the search pattern that the mailbox name should match
* - url string the webhook URL where inbound messages will be published
*/
public function addRoute($domain, $pattern, $url)
{
$_params = array("domain" => $domain, "pattern" => $pattern, "url" => $url);
return $this->master->call('inbound/add-route', $_params);
}
/**
* Update the pattern or webhook of an existing inbound mailbox route. If null is provided for any fields, the values will remain unchanged.
* @param string $id the unique identifier of an existing mailbox route
* @param string $pattern the search pattern that the mailbox name should match
* @param string $url the webhook URL where the inbound messages will be published
* @return struct the updated mailbox route information
* - id string the unique identifier of the route
* - pattern string the search pattern that the mailbox name should match
* - url string the webhook URL where inbound messages will be published
*/
public function updateRoute($id, $pattern = null, $url = null)
{
$_params = array("id" => $id, "pattern" => $pattern, "url" => $url);
return $this->master->call('inbound/update-route', $_params);
}
/**
* Delete an existing inbound mailbox route
* @param string $id the unique identifier of an existing route
* @return struct the deleted mailbox route information
* - id string the unique identifier of the route
* - pattern string the search pattern that the mailbox name should match
* - url string the webhook URL where inbound messages will be published
*/
public function deleteRoute($id)
{
$_params = array("id" => $id);
return $this->master->call('inbound/delete-route', $_params);
}
/**
* Take a raw MIME document destined for a domain with inbound domains set up, and send it to the inbound hook exactly as if it had been sent over SMTP
* @param string $rawMessage the full MIME document of an email message
* @param array|null $to optionally define the recipients to receive the message - otherwise we'll use the To, Cc, and Bcc headers provided in the document
* - to[] string the email address of the recipient
* @param string $mailFrom the address specified in the MAIL FROM stage of the SMTP conversation. Required for the SPF check.
* @param string $helo the identification provided by the client mta in the MTA state of the SMTP conversation. Required for the SPF check.
* @param string $clientAddress the remote MTA's ip address. Optional; required for the SPF check.
* @return array an array of the information for each recipient in the message (usually one) that matched an inbound route
* - return[] struct the individual recipient information
* - email string the email address of the matching recipient
* - pattern string the mailbox route pattern that the recipient matched
* - url string the webhook URL that the message was posted to
*/
public function sendRaw($rawMessage, $to = null, $mailFrom = null, $helo = null, $clientAddress = null)
{
$_params = array("raw_message" => $rawMessage, "to" => $to, "mail_from" => $mailFrom, "helo" => $helo, "client_address" => $clientAddress);
return $this->master->call('inbound/send-raw', $_params);
}
}
<?php
class Mandrill_Internal
{
public function __construct(Mandrill_Mandrill $master)
{
$this->master = $master;
}
}
<?php
/**
* The provided API key is not a valid Mandrill API key
*/
class Mandrill_Invalid_Key extends Mandrill_Error
{
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
<?php
class Mandrill_Metadata
{
public function __construct(Mandrill_Mandrill $master)
{
$this->master = $master;
}
/**
* Get the list of custom metadata fields indexed for the account.
* @return array the custom metadata fields for the account
* - return[] struct the individual custom metadata field info
* - name string the unique identifier of the metadata field to update
* - state string the current state of the metadata field, one of "active", "delete", or "index"
* - view_template string Mustache template to control how the metadata is rendered in your activity log
*/
public function getList()
{
$_params = array();
return $this->master->call('metadata/list', $_params);
}
/**
* Add a new custom metadata field to be indexed for the account.
* @param string $name a unique identifier for the metadata field
* @param string $viewTemplate optional Mustache template to control how the metadata is rendered in your activity log
* @return struct the information saved about the new metadata field
* - name string the unique identifier of the metadata field to update
* - state string the current state of the metadata field, one of "active", "delete", or "index"
* - view_template string Mustache template to control how the metadata is rendered in your activity log
*/
public function add($name, $viewTemplate = null)
{
$_params = array("name" => $name, "view_template" => $viewTemplate);
return $this->master->call('metadata/add', $_params);
}
/**
* Update an existing custom metadata field.
* @param string $name the unique identifier of the metadata field to update
* @param string $viewTemplate optional Mustache template to control how the metadata is rendered in your activity log
* @return struct the information for the updated metadata field
* - name string the unique identifier of the metadata field to update
* - state string the current state of the metadata field, one of "active", "delete", or "index"
* - view_template string Mustache template to control how the metadata is rendered in your activity log
*/
public function update($name, $viewTemplate)
{
$_params = array("name" => $name, "view_template" => $viewTemplate);
return $this->master->call('metadata/update', $_params);
}
/**
* Delete an existing custom metadata field. Deletion isn't instataneous, and /metadata/list will continue to return the field until the asynchronous deletion process is complete.
* @param string $name the unique identifier of the metadata field to update
* @return struct the information for the deleted metadata field
* - name string the unique identifier of the metadata field to update
* - state string the current state of the metadata field, one of "active", "delete", or "index"
* - view_template string Mustache template to control how the metadata is rendered in your activity log
*/
public function delete($name)
{
$_params = array("name" => $name);
return $this->master->call('metadata/delete', $_params);
}
}
<?php
/**
* The requested feature requires payment.
*/
class Mandrill_PaymentRequired extends Mandrill_Error
{
}
\ No newline at end of file
<?php
class Mandrill_Rejects
{
public function __construct(Mandrill_Mandrill $master)
{
$this->master = $master;
}
/**
* Adds an email to your email rejection blacklist. Addresses that you
* add manually will never expire and there is no reputation penalty
* for removing them from your blacklist. Attempting to blacklist an
* address that has been whitelisted will have no effect.
* @param string $email an email address to block
* @param string $comment an optional comment describing the rejection
* @param string $subaccount an optional unique identifier for the subaccount to limit the blacklist entry
* @return struct a status object containing the address and the result of the operation
* - email string the email address you provided
* - added boolean whether the operation succeeded
*/
public function add($email, $comment = null, $subaccount = null)
{
$_params = array("email" => $email, "comment" => $comment, "subaccount" => $subaccount);
return $this->master->call('rejects/add', $_params);
}
/**
* Retrieves your email rejection blacklist. You can provide an email
* address to limit the results. Returns up to 1000 results. By default,
* entries that have expired are excluded from the results; set
* include_expired to true to include them.
* @param string $email an optional email address to search by
* @param boolean $includeExpired whether to include rejections that have already expired.
* @param string $subaccount an optional unique identifier for the subaccount to limit the blacklist
* @return array Up to 1000 rejection entries
* - return[] struct the information for each rejection blacklist entry
* - email string the email that is blocked
* - reason string the type of event (hard-bounce, soft-bounce, spam, unsub, custom) that caused this rejection
* - detail string extended details about the event, such as the SMTP diagnostic for bounces or the comment for manually-created rejections
* - created_at string when the email was added to the blacklist
* - last_event_at string the timestamp of the most recent event that either created or renewed this rejection
* - expires_at string when the blacklist entry will expire (this may be in the past)
* - expired boolean whether the blacklist entry has expired
* - sender struct the sender that this blacklist entry applies to, or null if none.
* - address string the sender's email address
* - created_at string the date and time that the sender was first seen by Mandrill as a UTC date string in YYYY-MM-DD HH:MM:SS format
* - sent integer the total number of messages sent by this sender
* - hard_bounces integer the total number of hard bounces by messages by this sender
* - soft_bounces integer the total number of soft bounces by messages by this sender
* - rejects integer the total number of rejected messages by this sender
* - complaints integer the total number of spam complaints received for messages by this sender
* - unsubs integer the total number of unsubscribe requests received for messages by this sender
* - opens integer the total number of times messages by this sender have been opened
* - clicks integer the total number of times tracked URLs in messages by this sender have been clicked
* - unique_opens integer the number of unique opens for emails sent for this sender
* - unique_clicks integer the number of unique clicks for emails sent for this sender
* - subaccount string the subaccount that this blacklist entry applies to, or null if none.
*/
public function getList($email = null, $includeExpired = false, $subaccount = null)
{
$_params = array("email" => $email, "include_expired" => $includeExpired, "subaccount" => $subaccount);
return $this->master->call('rejects/list', $_params);
}
/**
* Deletes an email rejection. There is no limit to how many rejections
* you can remove from your blacklist, but keep in mind that each deletion
* has an affect on your reputation.
* @param string $email an email address
* @param string $subaccount an optional unique identifier for the subaccount to limit the blacklist deletion
* @return struct a status object containing the address and whether the deletion succeeded.
* - email string the email address that was removed from the blacklist
* - deleted boolean whether the address was deleted successfully.
* - subaccount string the subaccount blacklist that the address was removed from, if any
*/
public function delete($email, $subaccount = null)
{
$_params = array("email" => $email, "subaccount" => $subaccount);
return $this->master->call('rejects/delete', $_params);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
/**
* The provided subaccount id does not exist.
*/
class Mandrill_Unknown_Subaccount extends Mandrill_Error
{
}
\ No newline at end of file
<?php
class Mandrill_HttpError extends Mandrill_Error
{
}
\ No newline at end of file
<?php
class Mandrill_Urls
{
public function __construct(Mandrill_Mandrill $master)
{
$this->master = $master;
}
/**
* Get the 100 most clicked URLs
* @return array the 100 most clicked URLs and their stats
* - return[] struct the individual URL stats
* - url string the URL to be tracked
* - sent integer the number of emails that contained the URL
* - clicks integer the number of times the URL has been clicked from a tracked email
* - unique_clicks integer the number of unique emails that have generated clicks for this URL
*/
public function getList()
{
$_params = array();
return $this->master->call('urls/list', $_params);
}
/**
* Return the 100 most clicked URLs that match the search query given
* @param string $q a search query
* @return array the 100 most clicked URLs matching the search query
* - return[] struct the URL matching the query
* - url string the URL to be tracked
* - sent integer the number of emails that contained the URL
* - clicks integer the number of times the URL has been clicked from a tracked email
* - unique_clicks integer the number of unique emails that have generated clicks for this URL
*/
public function search($q)
{
$_params = array("q" => $q);
return $this->master->call('urls/search', $_params);
}
/**
* Return the recent history (hourly stats for the last 30 days) for a url
* @param string $url an existing URL
* @return array the array of history information
* - return[] struct the information for a single hour
* - time string the hour as a UTC date string in YYYY-MM-DD HH:MM:SS format
* - sent integer the number of emails that were sent with the URL during the hour
* - clicks integer the number of times the URL was clicked during the hour
* - unique_clicks integer the number of unique clicks generated for emails sent with this URL during the hour
*/
public function timeSeries($url)
{
$_params = array("url" => $url);
return $this->master->call('urls/time-series', $_params);
}
/**
* Get the list of tracking domains set up for this account
* @return array the tracking domains and their status
* - return[] struct the individual tracking domain
* - domain string the tracking domain name
* - created_at string the date and time that the tracking domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
* - last_tested_at string when the domain's DNS settings were last tested as a UTC string in YYYY-MM-DD HH:MM:SS format
* - cname struct details about the domain's CNAME record
* - valid boolean whether the domain's CNAME record is valid for use with Mandrill
* - valid_after string when the domain's CNAME record will be considered valid for use with Mandrill as a UTC string in YYYY-MM-DD HH:MM:SS format. If set, this indicates that the record is valid now, but was previously invalid, and Mandrill will wait until the record's TTL elapses to start using it.
* - error string an error describing the CNAME record, or null if the record is correct
* - valid_tracking boolean whether this domain can be used as a tracking domain for email.
*/
public function trackingDomains()
{
$_params = array();
return $this->master->call('urls/tracking-domains', $_params);
}
/**
* Add a tracking domain to your account
* @param string $domain a domain name
* @return struct information about the domain
* - domain string the tracking domain name
* - created_at string the date and time that the tracking domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
* - last_tested_at string when the domain's DNS settings were last tested as a UTC string in YYYY-MM-DD HH:MM:SS format
* - cname struct details about the domain's CNAME record
* - valid boolean whether the domain's CNAME record is valid for use with Mandrill
* - valid_after string when the domain's CNAME record will be considered valid for use with Mandrill as a UTC string in YYYY-MM-DD HH:MM:SS format. If set, this indicates that the record is valid now, but was previously invalid, and Mandrill will wait until the record's TTL elapses to start using it.
* - error string an error describing the CNAME record, or null if the record is correct
* - valid_tracking boolean whether this domain can be used as a tracking domain for email.
*/
public function addTrackingDomain($domain)
{
$_params = array("domain" => $domain);
return $this->master->call('urls/add-tracking-domain', $_params);
}
/**
* Checks the CNAME settings for a tracking domain. The domain must have been added already with the add-tracking-domain call
* @param string $domain an existing tracking domain name
* @return struct information about the tracking domain
* - domain string the tracking domain name
* - created_at string the date and time that the tracking domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
* - last_tested_at string when the domain's DNS settings were last tested as a UTC string in YYYY-MM-DD HH:MM:SS format
* - cname struct details about the domain's CNAME record
* - valid boolean whether the domain's CNAME record is valid for use with Mandrill
* - valid_after string when the domain's CNAME record will be considered valid for use with Mandrill as a UTC string in YYYY-MM-DD HH:MM:SS format. If set, this indicates that the record is valid now, but was previously invalid, and Mandrill will wait until the record's TTL elapses to start using it.
* - error string an error describing the CNAME record, or null if the record is correct
* - valid_tracking boolean whether this domain can be used as a tracking domain for email.
*/
public function checkTrackingDomain($domain)
{
$_params = array("domain" => $domain);
return $this->master->call('urls/check-tracking-domain', $_params);
}
}
This diff is collapsed.
<?php
class Mandrill_ValidationError extends Mandrill_Error
{
}
\ No newline at end of file
<?php
class Mandrill_Webhooks
{
public function __construct(Mandrill_Mandrill $master)
{
$this->master = $master;
}
/**
* Get the list of all webhooks defined on the account
* @return array the webhooks associated with the account
* - return[] struct the individual webhook info
* - id integer a unique integer indentifier for the webhook
* - url string The URL that the event data will be posted to
* - description string a description of the webhook
* - auth_key string the key used to requests for this webhook
* - events array The message events that will be posted to the hook
* - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
* - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
* - batches_sent integer the number of event batches that have ever been sent to this webhook
* - events_sent integer the total number of events that have ever been sent to this webhook
* - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
*/
public function getList()
{
$_params = array();
return $this->master->call('webhooks/list', $_params);
}
/**
* Add a new webhook
* @param string $url the URL to POST batches of events
* @param string $description an optional description of the webhook
* @param array $events an optional list of events that will be posted to the webhook
* - events[] string the individual event to listen for
* @return struct the information saved about the new webhook
* - id integer a unique integer indentifier for the webhook
* - url string The URL that the event data will be posted to
* - description string a description of the webhook
* - auth_key string the key used to requests for this webhook
* - events array The message events that will be posted to the hook
* - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
* - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
* - batches_sent integer the number of event batches that have ever been sent to this webhook
* - events_sent integer the total number of events that have ever been sent to this webhook
* - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
*/
public function add($url, $description = null, $events = array())
{
$_params = array("url" => $url, "description" => $description, "events" => $events);
return $this->master->call('webhooks/add', $_params);
}
/**
* Given the ID of an existing webhook, return the data about it
* @param integer $id the unique identifier of a webhook belonging to this account
* @return struct the information about the webhook
* - id integer a unique integer indentifier for the webhook
* - url string The URL that the event data will be posted to
* - description string a description of the webhook
* - auth_key string the key used to requests for this webhook
* - events array The message events that will be posted to the hook
* - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
* - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
* - batches_sent integer the number of event batches that have ever been sent to this webhook
* - events_sent integer the total number of events that have ever been sent to this webhook
* - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
*/
public function info($id)
{
$_params = array("id" => $id);
return $this->master->call('webhooks/info', $_params);
}
/**
* Update an existing webhook
* @param integer $id the unique identifier of a webhook belonging to this account
* @param string $url the URL to POST batches of events
* @param string $description an optional description of the webhook
* @param array $events an optional list of events that will be posted to the webhook
* - events[] string the individual event to listen for
* @return struct the information for the updated webhook
* - id integer a unique integer indentifier for the webhook
* - url string The URL that the event data will be posted to
* - description string a description of the webhook
* - auth_key string the key used to requests for this webhook
* - events array The message events that will be posted to the hook
* - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
* - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
* - batches_sent integer the number of event batches that have ever been sent to this webhook
* - events_sent integer the total number of events that have ever been sent to this webhook
* - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
*/
public function update($id, $url, $description = null, $events = array())
{
$_params = array("id" => $id, "url" => $url, "description" => $description, "events" => $events);
return $this->master->call('webhooks/update', $_params);
}
/**
* Delete an existing webhook
* @param integer $id the unique identifier of a webhook belonging to this account
* @return struct the information for the deleted webhook
* - id integer a unique integer indentifier for the webhook
* - url string The URL that the event data will be posted to
* - description string a description of the webhook
* - auth_key string the key used to requests for this webhook
* - events array The message events that will be posted to the hook
* - events[] string the individual message event (send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject)
* - created_at string the date and time that the webhook was created as a UTC string in YYYY-MM-DD HH:MM:SS format
* - last_sent_at string the date and time that the webhook last successfully received events as a UTC string in YYYY-MM-DD HH:MM:SS format
* - batches_sent integer the number of event batches that have ever been sent to this webhook
* - events_sent integer the total number of events that have ever been sent to this webhook
* - last_error string if we've ever gotten an error trying to post to this webhook, the last error that we've seen
*/
public function delete($id)
{
$_params = array("id" => $id);
return $this->master->call('webhooks/delete', $_params);
}
}
<?php
class Mandrill_Whitelists
{
public function __construct(Mandrill_Mandrill $master)
{
$this->master = $master;
}
/**
* Adds an email to your email rejection whitelist. If the address is
* currently on your blacklist, that blacklist entry will be removed
* automatically.
* @param string $email an email address to add to the whitelist
* @param string $comment an optional description of why the email was whitelisted
* @return struct a status object containing the address and the result of the operation
* - email string the email address you provided
* - added boolean whether the operation succeeded
*/
public function add($email, $comment = null)
{
$_params = array("email" => $email, "comment" => $comment);
return $this->master->call('whitelists/add', $_params);
}
/**
* Retrieves your email rejection whitelist. You can provide an email
* address or search prefix to limit the results. Returns up to 1000 results.
* @param string $email an optional email address or prefix to search by
* @return array up to 1000 whitelist entries
* - return[] struct the information for each whitelist entry
* - email string the email that is whitelisted
* - detail string a description of why the email was whitelisted
* - created_at string when the email was added to the whitelist
*/
public function getList($email = null)
{
$_params = array("email" => $email);
return $this->master->call('whitelists/list', $_params);
}
/**
* Removes an email address from the whitelist.
* @param string $email the email address to remove from the whitelist
* @return struct a status object containing the address and whether the deletion succeeded
* - email string the email address that was removed from the blacklist
* - deleted boolean whether the address was deleted successfully
*/
public function delete($email)
{
$_params = array("email" => $email);
return $this->master->call('whitelists/delete', $_params);
}
}
<?php
/**
* Author : Ebizmarts <info@ebizmarts.com>
* Date : 8/14/14
* Time : 6:48 PM
* File : Message.php
* Module : Ebizmarts_Mandrill
*/
class Mandrill_Message extends Mandrill_Mandrill
{
protected $_attachments = array();
protected $_bcc = array();
protected $_bodyText = false;
protected $_bodyHtml = false;
protected $_subject = null;
protected $_from = null;
protected $_to = array();
protected $_headers = array();
protected $_fromName;
public function createAttachment($body,
$mimeType = Zend_Mime::TYPE_OCTETSTREAM,
$disposition = Zend_Mime::DISPOSITION_ATTACHMENT,
$encoding = Zend_Mime::ENCODING_BASE64,
$filename = null)
{
$att = array('type' => $mimeType, 'name' => $filename, 'content' => base64_encode($body));
array_push($this->_attachments, $att);
}
public function log($m)
{
$storeId = Mage::app()->getStore()->getId();
if (Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::ENABLE_LOG, $storeId)) {
Mage::log($m, Zend_Log::INFO, 'Mandrill.log');
}
}
public function getAttachments()
{
return $this->_attachments;
}
public function addBcc($bcc)
{
$storeId = Mage::app()->getStore()->getId();
if (is_array($bcc)) {
foreach ($bcc as $email) {
array_push($this->_bcc, $email);
}
} else {
array_push($this->_bcc, $bcc);
}
}
public function getBcc()
{
return $this->_bcc;
}
public function addTo($email, $name = '')
{
if (!is_array($email)) {
$email = array($name => $email);
}
foreach ($email as $n => $recipient) {
$this->_to[] = $recipient;
}
return $this;
}
public function getTo()
{
return $this->_to;
}
public function setBodyHtml($html, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE)
{
$this->_bodyHtml = $html;
}
public function getBodyHtml()
{
return $this->_bodyHtml;
}
public function setBodyText($txt, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE)
{
$this->_bodyText = $txt;
}
public function getBodyText()
{
return $this->_bodyText;
}
public function setSubject($subject)
{
if ($this->_subject === null) {
$subject = $this->_filterOther($subject);
$this->_subject = $subject;
}
return $this;
}
public function getSubject()
{
return $this->_subject;
}
public function setFrom($email, $name = null)
{
$email = $this->_filterEmail($email);
// $name = $this->_filterName($name);
$this->_from = $email;
$this->_fromName = $name;
// $this->_storeHeader('From', $this->_formatAddress($email, $name), true);
return $this;
}
public function getFrom()
{
return $this->_from;
}
protected function _filterEmail($email)
{
$rule = array("\r" => '',
"\n" => '',
"\t" => '',
'"' => '',
',' => '',
'<' => '',
'>' => '',
);
return strtr($email, $rule);
}
/**
* Filter of name data
*
* @param string $name
* @return string
*/
protected function _filterName($name)
{
$rule = array("\r" => '',
"\n" => '',
"\t" => '',
'"' => "'",
'<' => '[',
'>' => ']',
);
return trim(strtr($name, $rule));
}
protected function _filterOther($data)
{
$rule = array("\r" => '',
"\n" => '',
"\t" => '',
);
return strtr($data, $rule);
}
public function setReplyTo($email, $name = null)
{
$email = $this->_filterEmail($email);
$name = $this->_filterName($name);
$this->_headers[] = array('Reply-To' => sprintf('%s <%s>', $name, $email));
return $this;
}
public function addHeader($name, $value, $append = false)
{
$prohibit = array('to', 'cc', 'bcc', 'from', 'subject',
'reply-to', 'return-path',
'date', 'message-id',
);
if (in_array(strtolower($name), $prohibit)) {
/**
* @see Zend_Mail_Exception
*/
#require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('Cannot set standard header from addHeader()');
}
$this->_header[$name] = $value;
return $this;
}
public function getHeaders()
{
if (isset($this->_headers[0])) {
return $this->_headers[0];
} else {
return null;
}
}
public function send()
{
$email = array();
foreach ($this->_to as $to) {
$email['to'][] = array(
'email' => $to
);
}
foreach ($this->_bcc as $bcc) {
$email['to'][] = array(
'email' => $bcc,
'type' => 'bcc'
);
}
$email['subject'] = $this->_subject;
if (isset($this->_fromName)) {
$email['from_name'] = $this->_fromName;
}
$email['from_email'] = $this->_from;
if ($headers = $this->getHeaders()) {
$email['headers'] = $headers;
}
if ($att = $this->getAttachments()) {
$email['attachments'] = $att;
}
if ($this->_bodyHtml) {
$email['html'] = $this->_bodyHtml;
}
if ($this->_bodyText) {
$email['text'] = $this->_bodyText;
}
try {
$result = $this->messages->send($email);
} catch (Exception $e) {
Mage::logException($e);
return false;
}
return true;
}
}
\ No newline at end of file
ul.tabs a.ebizmarts-section:hover {
background-color: #D8E6E6;
background-image: url(../images/tabs_link_over_bg.gif);
}
ul.tabs a.ebizmarts-section {
border-bottom: 1px;
border-bottom-style: dotted;
}
ul.tabs a.ebizmarts-section:hover {
border-bottom: 1px;
border-bottom-style: dotted;
}
ul.tabs a.ebizmarts-section span,
ul.tabs a.ebizmarts-section:hover span {
overflow: hidden;
padding-top: 5px;
}
ul.tabs a.ebizmarts-section.active, ul.tabs a.ebizmarts-section.active.last, ul.tabs a.ebizmarts-section.active:hover {
background-color: white;
border-bottom-color: #8BA5A5;
}
ul.tabs a.ebizmarts-section.last {
border-bottom: none;
}
small {
font-size: 9px;
}
div.ebizmarts-notice {
background: none repeat scroll 0 0 #EAF0EE;
border: 1px solid #CCCCCC;
margin-bottom: 10px;
padding: 11px 0 0 10px;
}
h3.ebizmarts-header {
height: 22px;
overflow: hidden;
padding: 0;
text-indent: -9999px;
}
\ No newline at end of file
ul.tabs a.mandrill-section:hover {
background-color: #D8E6E6;
background-image: url(../../images/tabs_link_over_bg.gif);
}
ul.tabs a.mandrill-section {
border-bottom: 1px;
border-bottom-style: dotted;
}
ul.tabs a.mandrill-section:hover {
border-bottom: 1px;
border-bottom-style: dotted;
}
ul.tabs a.mandrill-section span,
ul.tabs a.mandrill-section:hover span {
background: url(mandrill-tab.png) no-repeat 17px 3px;
overflow: hidden;
padding: 0;
padding-left: 43px;
width: 120px;
height: 24px;
line-height: 24px;
}
ul.tabs a.mandrill-section.active, ul.tabs a.mandrill-section.active:hover {
background-color: white;
border-bottom-color: #8BA5A5;
}
small {
font-size: 9px;
}
div.mandrill-notice {
background: none repeat scroll 0 0 #EAF0EE;
border: 1px solid #CCCCCC;
margin-bottom: 10px;
padding: 11px 0 0 10px;
}
h3.mandrill-header {
background: url("mandrill-tab.png") no-repeat scroll 0 0 transparent;
height: 22px;
overflow: hidden;
padding: 0;
text-indent: -9999px;
width: 120px;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment