FreeLunchLabs_MailGun - Version 1.0.0

Version Notes

First stable release

Download this release

Release Info

Developer Charles Drew
Extension FreeLunchLabs_MailGun
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (34) hide show
  1. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Customer/Email.php +13 -0
  2. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Customer/Email/Grid.php +66 -0
  3. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Customer/Tab/Mailgun.php +37 -0
  4. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Emailtracking.php +75 -0
  5. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Event/Container.php +13 -0
  6. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Event/Grid.php +50 -0
  7. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Event/Renderer/Timestamp.php +10 -0
  8. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Event/Renderer/Type.php +9 -0
  9. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Global/Container.php +13 -0
  10. app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Global/Grid.php +66 -0
  11. app/code/community/FreeLunchLabs/MailGun/Helper/Data.php +5 -0
  12. app/code/community/FreeLunchLabs/MailGun/Model/Email.php +48 -0
  13. app/code/community/FreeLunchLabs/MailGun/Model/Email/Template.php +133 -0
  14. app/code/community/FreeLunchLabs/MailGun/Model/Event.php +36 -0
  15. app/code/community/FreeLunchLabs/MailGun/Model/Exceptions/InvalidParameter.php +5 -0
  16. app/code/community/FreeLunchLabs/MailGun/Model/Exceptions/InvalidParameterType.php +5 -0
  17. app/code/community/FreeLunchLabs/MailGun/Model/Exceptions/MissingRequiredMIMEParameters.php +5 -0
  18. app/code/community/FreeLunchLabs/MailGun/Model/Exceptions/TooManyParameters.php +5 -0
  19. app/code/community/FreeLunchLabs/MailGun/Model/Mailgun.php +120 -0
  20. app/code/community/FreeLunchLabs/MailGun/Model/Messagebuilder.php +296 -0
  21. app/code/community/FreeLunchLabs/MailGun/Model/Resource/Email.php +26 -0
  22. app/code/community/FreeLunchLabs/MailGun/Model/Resource/Email/Collection.php +38 -0
  23. app/code/community/FreeLunchLabs/MailGun/Model/Resource/Event.php +10 -0
  24. app/code/community/FreeLunchLabs/MailGun/Model/Resource/Event/Collection.php +11 -0
  25. app/code/community/FreeLunchLabs/MailGun/controllers/Adminhtml/EmailtrackingController.php +96 -0
  26. app/code/community/FreeLunchLabs/MailGun/etc/config.xml +151 -0
  27. app/code/community/FreeLunchLabs/MailGun/etc/system.xml +111 -0
  28. app/code/community/FreeLunchLabs/MailGun/sql/mailgun_setup/mysql4-install-1.0.0.php +38 -0
  29. app/design/adminhtml/default/default/layout/mailgun.xml +21 -0
  30. app/design/adminhtml/default/default/template/mailgun/customer/tab/tab.phtml +1 -0
  31. app/design/adminhtml/default/default/template/mailgun/emaildetail.phtml +90 -0
  32. app/design/adminhtml/default/default/template/mailgun/globalemailgrid.phtml +15 -0
  33. app/etc/modules/FreeLunchLabs_MailGun.xml +9 -0
  34. package.xml +20 -0
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Customer/Email.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Customer_Email extends Mage_Adminhtml_Block_Widget_Grid_Container {
4
+
5
+ protected function _construct() {
6
+ parent::_construct();
7
+
8
+ $this->_blockGroup = 'freelunchlabs_mailgun';
9
+ $this->_controller = 'adminhtml_customer_email';
10
+ $this->_headerText = false;
11
+
12
+ }
13
+ }
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Customer/Email/Grid.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Customer_Email_Grid extends Mage_Adminhtml_Block_Widget_Grid {
4
+
5
+ public function __construct() {
6
+ parent::__construct();
7
+ $this->setId('mailgun_email_grid');
8
+ $this->setDefaultSort('id');
9
+ $this->setDefaultDir('ASC');
10
+ $this->setUseAjax(true);
11
+ $this->setFilterVisibility(true);
12
+ }
13
+
14
+ protected function _prepareCollection() {
15
+ $collection = Mage::getResourceModel('freelunchlabs_mailgun/email_collection')->getGridCollection();
16
+
17
+ //Filter on Customer
18
+ $collection->addFieldToFilter('customer_id', Mage::registry('current_customer')->getId());
19
+
20
+ $this->setCollection($collection);
21
+ return parent::_prepareCollection();
22
+ }
23
+
24
+ protected function _prepareColumns() {
25
+
26
+ $this->addColumn('subject', array(
27
+ 'header' => 'Subject',
28
+ 'type' => 'text',
29
+ 'index' => 'subject'
30
+ ));
31
+
32
+ $this->addColumn('mailgun_id', array(
33
+ 'header' => 'Mailgun ID',
34
+ 'type' => 'text',
35
+ 'index' => 'mailgun_id'
36
+ ));
37
+
38
+ $this->addColumn('current_status', array(
39
+ 'header' => 'Latest Status',
40
+ 'index' => 'current_status',
41
+ 'renderer' => 'FreeLunchLabs_MailGun_Block_Adminhtml_Event_Renderer_Type'
42
+ ));
43
+
44
+ $this->addColumn('date_sent', array(
45
+ 'header' => 'Date Sent',
46
+ 'type' => 'datetime',
47
+ 'index' => 'date_sent'
48
+ ));
49
+
50
+ return parent::_prepareColumns();
51
+ }
52
+
53
+ public function getRowUrl($row) {
54
+ return $this->getUrl('*/emailtracking/emaildetail', array(
55
+ 'id' => $row->getId()
56
+ ));
57
+ }
58
+
59
+ public function getGridUrl() {
60
+ return $this->getUrl('*/emailtracking/emailgrid', array(
61
+ '_current' => true,
62
+ 'id' => Mage::registry('current_customer')->getId()
63
+ ));
64
+ }
65
+
66
+ }
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Customer/Tab/Mailgun.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Customer_Tab_Mailgun extends Mage_Adminhtml_Block_Template implements Mage_Adminhtml_Block_Widget_Tab_Interface {
4
+
5
+ public function _construct() {
6
+ parent::_construct();
7
+
8
+ $this->setTemplate('mailgun/customer/tab/tab.phtml');
9
+ }
10
+
11
+ public function getTabLabel() {
12
+ return $this->__('Email Tracking');
13
+ }
14
+
15
+ public function getTabTitle() {
16
+ return $this->__('View emails sent to this customer and the email history');
17
+ }
18
+
19
+ public function canShowTab() {
20
+ return Mage::getStoreConfig('mailgun/events/store');
21
+ }
22
+
23
+ public function isHidden() {
24
+ return false;
25
+ }
26
+
27
+ public function getAfter() {
28
+ return 'tags';
29
+ }
30
+
31
+ public function getGrid() {
32
+ $gridBlock = $this->getLayout()->createBlock('freelunchlabs_mailgun/adminhtml_customer_email');
33
+
34
+ return $gridBlock->getGridHtml();
35
+ }
36
+
37
+ }
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Emailtracking.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Emailtracking extends Mage_Adminhtml_Block_Template {
4
+
5
+ function getFetchActivityUrl() {
6
+ return $this->getUrl('*/*/getEmailEvents');
7
+ }
8
+
9
+ public function getEmailDetail() {
10
+ $email = Mage::registry('current_email');
11
+
12
+ if ($email->getCustomerId()) {
13
+ $customer = Mage::getModel('customer/customer')->load($email->getCustomerId());
14
+ $email->setCustomer($customer);
15
+ }
16
+
17
+ return $email;
18
+ }
19
+
20
+ public function getBackButtonHtml() {
21
+ return $this->getLayout()->createBlock('adminhtml/widget')->getButtonHtml('Back', 'history.back()', 'back');
22
+ }
23
+
24
+ public function getViewEmailBodyButtonHtml($emailId) {
25
+ $url = $this->getUrl('*/*/emailView', array(
26
+ 'id' => $emailId
27
+ ));
28
+
29
+ $onClick = "window.open('{$url}','name','width=700,height=800')";
30
+
31
+ return $this->getLayout()->createBlock('adminhtml/widget')->getButtonHtml('View Email Body', $onClick);
32
+ }
33
+
34
+ public function getEditCustomerUrl($customerId) {
35
+ return $url = $this->getUrl('*/customer/edit', array(
36
+ 'id' => $customerId
37
+ ));
38
+ }
39
+
40
+ public function getCustomerGroupName($customerGroupId) {
41
+ return Mage::getModel('customer/group')->load($customerGroupId)->getCustomerGroupCode();
42
+ }
43
+
44
+ public function formatCustomerCreateDate($createdTimestamp) {
45
+ return Mage::helper('core')->formatDate($createdTimestamp, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
46
+ }
47
+
48
+ public function getFetch24HoursOfEmailActivityButton() {
49
+ $onClick = "setLocation('{$this->getFetchActivityUrl()}')";
50
+
51
+ return $this->getLayout()->createBlock('adminhtml/widget')->getButtonHtml('Fetch Past 24 Hours of Email Activity', $onClick);
52
+ }
53
+
54
+ public function getDeleteEmailTrackingLogsDaysButton() {
55
+ $days = Mage::getStoreConfig('mailgun/events/days');
56
+
57
+ if ($days) {
58
+ $url = $this->getUrl('*/*/deleteEmailTrackingLogsDays');
59
+ $onClick = "confirmSetLocation('Are you sure?', '{$url}')";
60
+
61
+ return $this->getLayout()->createBlock('adminhtml/widget')->getButtonHtml("Delete Email Records Older Than {$days} Days", $onClick, 'delete');
62
+ } else {
63
+ return "";
64
+ }
65
+ }
66
+
67
+ public function getDeleteAllEmailTrackingLogsButton() {
68
+ $url = $this->getUrl('*/*/deleteEmailTrackingLogs');
69
+ $onClick = "confirmSetLocation('Are you sure?', '{$url}')";
70
+
71
+ return $this->getLayout()->createBlock('adminhtml/widget')->getButtonHtml('Delete All Email Records', $onClick, 'delete');
72
+ }
73
+
74
+ }
75
+
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Event/Container.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Event_Container extends Mage_Adminhtml_Block_Widget_Grid_Container {
4
+
5
+ protected function _construct() {
6
+ parent::_construct();
7
+
8
+ $this->_blockGroup = 'freelunchlabs_mailgun';
9
+ $this->_controller = 'adminhtml_event';
10
+ $this->_headerText = false;
11
+
12
+ }
13
+ }
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Event/Grid.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Event_Grid extends Mage_Adminhtml_Block_Widget_Grid {
4
+
5
+ public function __construct() {
6
+ parent::__construct();
7
+ $this->setId('mailgun_event_grid');
8
+ $this->setDefaultSort('timestamp');
9
+ $this->setDefaultDir('ASC');
10
+ $this->setUseAjax(false);
11
+ $this->setFilterVisibility(false);
12
+ }
13
+
14
+ protected function _prepareCollection() {
15
+ $collection = Mage::getResourceModel('freelunchlabs_mailgun/event_collection');
16
+ $collection->addFieldToFilter('email_id', Mage::registry('current_email')->getId());
17
+
18
+ $this->setCollection($collection);
19
+ return parent::_prepareCollection();
20
+ }
21
+
22
+ protected function _prepareColumns() {
23
+
24
+ $this->addColumn('event_type', array(
25
+ 'header' => 'Event',
26
+ 'index' => 'event_type',
27
+ 'renderer' => 'FreeLunchLabs_MailGun_Block_Adminhtml_Event_Renderer_Type'
28
+ ));
29
+
30
+ $this->addColumn('timestamp', array(
31
+ 'header' => 'Event Time',
32
+ 'index' => 'timestamp',
33
+ 'renderer' => 'FreeLunchLabs_MailGun_Block_Adminhtml_Event_Renderer_Timestamp'
34
+ ));
35
+
36
+ return parent::_prepareColumns();
37
+ }
38
+
39
+ public function getRowUrl($row) {
40
+ return null;
41
+ }
42
+
43
+ public function getGridUrl() {
44
+ return $this->getUrl('*/emailTracking/emailDetail', array(
45
+ '_current' => true,
46
+ 'id' => Mage::registry('current_email')->getId()
47
+ ));
48
+ }
49
+
50
+ }
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Event/Renderer/Timestamp.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Event_Renderer_Timestamp extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
3
+ {
4
+ public function render(Varien_Object $row)
5
+ {
6
+ $value = $row->getData($this->getColumn()->getIndex());
7
+ $date = Mage::getSingleton('core/date')->date(null, $value);
8
+ return Mage::helper('core')->formatDate(new Zend_Date($date), 'medium', true);
9
+ }
10
+ }
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Event/Renderer/Type.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Event_Renderer_Type extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
3
+ {
4
+ public function render(Varien_Object $row)
5
+ {
6
+ $value = $row->getData($this->getColumn()->getIndex());
7
+ return ucwords($value);
8
+ }
9
+ }
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Global/Container.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Global_Container extends Mage_Adminhtml_Block_Widget_Grid_Container {
4
+
5
+ protected function _construct() {
6
+ parent::_construct();
7
+
8
+ $this->_blockGroup = 'freelunchlabs_mailgun';
9
+ $this->_controller = 'adminhtml_global';
10
+ $this->_headerText = false;
11
+
12
+ }
13
+ }
app/code/community/FreeLunchLabs/MailGun/Block/Adminhtml/Global/Grid.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Block_Adminhtml_Global_Grid extends Mage_Adminhtml_Block_Widget_Grid {
4
+
5
+ public function __construct() {
6
+ parent::__construct();
7
+ $this->setId('mailgun_global_grid');
8
+ $this->setDefaultSort('date_sent');
9
+ $this->setDefaultDir('ASC');
10
+ $this->setUseAjax(false);
11
+ $this->setFilterVisibility(true);
12
+ }
13
+
14
+ protected function _prepareCollection() {
15
+ $collection = Mage::getResourceModel('freelunchlabs_mailgun/email_collection')->getGridCollection();
16
+
17
+ $this->setCollection($collection);
18
+ return parent::_prepareCollection();
19
+ }
20
+
21
+ protected function _prepareColumns() {
22
+
23
+ $this->addColumn('subject', array(
24
+ 'header' => 'Subject',
25
+ 'type' => 'text',
26
+ 'index' => 'subject'
27
+ ));
28
+
29
+ $this->addColumn('email_address', array(
30
+ 'header' => 'Recipient Address',
31
+ 'type' => 'email',
32
+ 'index' => 'email_address'
33
+ ));
34
+
35
+ $this->addColumn('mailgun_id', array(
36
+ 'header' => 'Mailgun ID',
37
+ 'type' => 'text',
38
+ 'index' => 'mailgun_id'
39
+ ));
40
+
41
+ $this->addColumn('current_status', array(
42
+ 'header' => 'Latest Status',
43
+ 'index' => 'current_status',
44
+ 'renderer' => 'FreeLunchLabs_MailGun_Block_Adminhtml_Event_Renderer_Type'
45
+ ));
46
+
47
+ $this->addColumn('date_sent', array(
48
+ 'header' => 'Date Sent',
49
+ 'type' => 'datetime',
50
+ 'index' => 'date_sent'
51
+ ));
52
+
53
+ return parent::_prepareColumns();
54
+ }
55
+
56
+ public function getRowUrl($row) {
57
+ return $this->getUrl('*/emailtracking/emaildetail', array(
58
+ 'id' => $row->getId()
59
+ ));
60
+ }
61
+
62
+ public function getGridUrl() {
63
+ return $this->getUrl('*/emailtracking');
64
+ }
65
+
66
+ }
app/code/community/FreeLunchLabs/MailGun/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ }
app/code/community/FreeLunchLabs/MailGun/Model/Email.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Email extends Mage_Core_Model_Abstract {
4
+
5
+ protected function _construct() {
6
+ $this->_init('freelunchlabs_mailgun/email');
7
+ }
8
+
9
+ public function saveInitialSend($message, $sendResponse) {
10
+ $customer = Mage::getModel('customer/customer');
11
+ $customer->setWebsiteId($message->getStore()->getWebsite()->getId());
12
+ $customer->loadByEmail($message->getPrimaryRecipient());
13
+
14
+ if ($customer) {
15
+ $this->setCustomerId($customer->getId());
16
+ }
17
+
18
+ $this->setEmailAddress($message->getPrimaryRecipient());
19
+ $this->setMailgunId(str_replace(array("<", ">"), "", $sendResponse->id));
20
+ $this->setSubject($message->getSubject());
21
+ $this->setBody($message->getHtmlBody());
22
+ $this->setDateSent(Mage::getSingleton('core/date')->gmtTimestamp());
23
+ $this->save();
24
+
25
+ Mage::getModel('freelunchlabs_mailgun/event')->logEmailEvent($this->getId(), FreeLunchLabs_MailGun_Model_Event::GENERATED, $this);
26
+ }
27
+
28
+ public function loadByMailgunIdAndRecipient($mailgunId, $recipient) {
29
+ $collection = $this->getCollection();
30
+ $collection->addFieldToFilter('mailgun_id', $mailgunId);
31
+ $collection->addFieldToFilter('email_address', $recipient);
32
+
33
+ return $collection->getFirstItem();
34
+ }
35
+
36
+ public function deleteEmailTrackingLogsDays() {
37
+ $days = Mage::getStoreConfig('mailgun/events/days');
38
+
39
+ if ($days) {
40
+ $this->deleteEmailTrackingLogs($days);
41
+ }
42
+ }
43
+
44
+ public function deleteEmailTrackingLogs($days = false) {
45
+ $this->getResource()->deleteEmailTrackingLogs($days);
46
+ }
47
+
48
+ }
app/code/community/FreeLunchLabs/MailGun/Model/Email/Template.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Email_Template extends Mage_Core_Model_Email_Template {
4
+
5
+ var $bcc = null;
6
+ var $replyto = null;
7
+ var $returnPath = null; //This is not used because MailGun overides it for their internal purposes.
8
+
9
+ public function send($email, $name = null, array $variables = array()) {
10
+ //Get appropriate store
11
+ if(isset($variables['store'])) {
12
+ $store = $variables['store'];
13
+ } elseif($this->getDesignConfig()->getStore()) {
14
+ $store = Mage::getModel('core/store')->load($this->getDesignConfig()->getStore());
15
+ } else {
16
+ $store = Mage::app()->getStore();
17
+ }
18
+
19
+ if ($store->getConfig('mailgun/general/active')) {
20
+ if (!$this->isValidForSend()) {
21
+ Mage::logException(new Exception('This letter cannot be sent.'));
22
+ return false;
23
+ }
24
+
25
+ $message = Mage::getModel('freelunchlabs_mailgun/messagebuilder');
26
+
27
+ //Recipient(s)
28
+ $emails = array_values((array) $email);
29
+ $names = is_array($name) ? $name : (array) $name;
30
+ $names = array_values($names);
31
+ foreach ($emails as $key => $email) {
32
+ if (!isset($names[$key])) {
33
+ $names[$key] = substr($email, 0, strpos($email, '@'));
34
+ }
35
+ }
36
+
37
+ $variables['email'] = reset($emails);
38
+ $variables['name'] = reset($names);
39
+
40
+ //Add To Recipients
41
+ $isPrimary = true;
42
+ foreach ($emails as $key => $email) {
43
+ if($isPrimary) {
44
+ //Add primary recipient
45
+ $message->setPrimaryRecipient($email);
46
+ }
47
+ $isPrimary = false;
48
+
49
+ $message->addToRecipient($names[$key] . " <" . $email . ">");
50
+ }
51
+
52
+ //Subject
53
+ $subject = $this->getProcessedTemplateSubject($variables);
54
+ $message->setSubject($subject);
55
+
56
+ //From Name
57
+ $message->setFromAddress($this->getSenderName() . " <" . $this->getSenderEmail() . ">");
58
+
59
+ //Bcc
60
+ if (is_array($this->bcc)) {
61
+ foreach ($this->bcc as $bcc_email) {
62
+ $message->addBccRecipient($bcc_email);
63
+ }
64
+ } elseif ($this->bcc) {
65
+ $message->addBccRecipient($this->bcc);
66
+ }
67
+
68
+ //Reply To
69
+ if (!is_null($this->replyto)) {
70
+ $message->setReplyToAddress($this->replyto);
71
+ }
72
+
73
+ //Message Body
74
+ $this->setUseAbsoluteLinks(true);
75
+ $processedTemplateBody = $this->getProcessedTemplate($variables, true);
76
+
77
+ if ($this->isPlain()) {
78
+ $message->setTextBody($processedTemplateBody);
79
+ } else {
80
+ $message->setHtmlBody($processedTemplateBody);
81
+ }
82
+
83
+ //Add Unique Args
84
+ $message->addCustomData("message_data", array('id' => 123456));
85
+
86
+ //Tag message with type
87
+ $message->addTag($this->getTemplateId());
88
+ $message->addTag($store->getConfig('mailgun/general/tag'));
89
+
90
+ if($store->getConfig('mailgun/events/opens')) {
91
+ $message->setOpenTracking(true);
92
+ }
93
+
94
+ if($store->getConfig('mailgun/events/clicks')) {
95
+ $message->setClickTracking(true);
96
+ }
97
+
98
+ //Set store
99
+ $message->setStore($store);
100
+
101
+ //Send it!
102
+ try {
103
+ Mage::getModel('freelunchlabs_mailgun/mailgun')->send($message);
104
+ $this->_mail = null;
105
+ } catch (Exception $e) {
106
+ $this->_mail = null;
107
+ Mage::logException($e);
108
+ return false;
109
+ }
110
+
111
+ return true;
112
+ } else {
113
+ return parent::send($email, $name, $variables);
114
+ }
115
+ }
116
+
117
+ public function addBcc($bcc) {
118
+ $this->bcc = $bcc;
119
+ return parent::addBcc($bcc);
120
+ }
121
+
122
+ public function setReturnPath($email) {
123
+ $this->returnPath = $email;
124
+ return parent::setReturnPath($email);
125
+
126
+ }
127
+
128
+ public function setReplyTo($email) {
129
+ $this->replyto = $email;
130
+ return parent::setReplyTo($email);
131
+ }
132
+
133
+ }
app/code/community/FreeLunchLabs/MailGun/Model/Event.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Event extends Mage_Core_Model_Abstract {
4
+ //Event types
5
+
6
+ const GENERATED = "generated";
7
+ const ACCEPTED = "accepted";
8
+ const REJECTED = "rejected";
9
+ const DELIVERED = "delivered";
10
+ const FAILED = "failed";
11
+ const OPENED = "opened";
12
+ const CLICKED = "clicked";
13
+ const UNSUBSCRIBED = "unsubscribed";
14
+ const COMPLAINED = "complained";
15
+ const STORED = "stored";
16
+
17
+ protected function _construct() {
18
+ $this->_init('freelunchlabs_mailgun/event');
19
+ }
20
+
21
+ public function logEmailEvent($emailId, $eventType, $email = false) {
22
+ $this->setEmailId($emailId);
23
+ $this->setEventType($eventType);
24
+ $this->setTimestamp(Mage::getSingleton('core/date')->gmtTimestamp());
25
+ $this->save();
26
+ }
27
+
28
+ public function loadByTimestampAndEmailId($timestamp, $emailId) {
29
+ $collection = $this->getCollection();
30
+ $collection->addFieldToFilter('timestamp', $timestamp);
31
+ $collection->addFieldToFilter('email_id', $emailId);
32
+
33
+ return $collection->getFirstItem();
34
+ }
35
+
36
+ }
app/code/community/FreeLunchLabs/MailGun/Model/Exceptions/InvalidParameter.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Exceptions_InvalidParameter extends \Exception{}
4
+
5
+ ?>
app/code/community/FreeLunchLabs/MailGun/Model/Exceptions/InvalidParameterType.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Exceptions_InvalidParameterType extends \Exception{}
4
+
5
+ ?>
app/code/community/FreeLunchLabs/MailGun/Model/Exceptions/MissingRequiredMIMEParameters.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Exceptions_MissingRequiredMIMEParameters extends \Exception{}
4
+
5
+ ?>
app/code/community/FreeLunchLabs/MailGun/Model/Exceptions/TooManyParameters.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Exceptions_TooManyParameters extends \Exception{}
4
+
5
+ ?>
app/code/community/FreeLunchLabs/MailGun/Model/Mailgun.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Mailgun extends Mage_Core_Model_Abstract {
4
+
5
+ public $apiUrl = "https://api.mailgun.net/v2/";
6
+
7
+ public function mailgunRequest($type, $domain, $apiKey, $data, $method = Zend_Http_Client::GET, $uriOveride = false) {
8
+
9
+ $client = new Zend_Http_Client();
10
+ $client->setAuth("api", $apiKey);
11
+ $client->setMethod($method);
12
+
13
+ if($uriOveride) {
14
+ $client->setUri($uriOveride);
15
+ } else {
16
+ $client->setUri($this->apiUrl . $domain . "/" . $type);
17
+ }
18
+
19
+ if($method == Zend_Http_Client::POST) {
20
+ foreach($data as $key => $value) {
21
+ $client->setParameterPost($key, $value);
22
+ }
23
+ } else {
24
+ foreach($data as $key => $value) {
25
+ $client->setParameterGet($key, $value);
26
+ }
27
+ }
28
+
29
+ try {
30
+ $response = $client->request();
31
+
32
+ if($response->getStatus() == 200) {
33
+ return json_decode($response->getBody());
34
+ } else {
35
+ throw new Zend_Http_Exception("Error connecting to MailGun API. Returned error code: " . $response->getStatus() . " --- " . $response->getBody());
36
+ }
37
+ } catch (Exception $e) {
38
+ Mage::logException($e);
39
+ return false;
40
+ }
41
+ }
42
+
43
+ public function send($message) {
44
+
45
+ $domain = $message->getStore()->getConfig('mailgun/general/domain');
46
+ $apiKey = $message->getStore()->getConfig('mailgun/general/key');
47
+
48
+ $sendResponse = $this->mailgunRequest('messages', $domain, $apiKey, $message->getMessage(), Zend_Http_Client::POST);
49
+
50
+ if($message->getStore()->getConfig('mailgun/events/store')) {
51
+ Mage::getModel('freelunchlabs_mailgun/email')->saveInitialSend($message, $sendResponse);
52
+ }
53
+
54
+ return $sendResponse;
55
+ }
56
+
57
+ public function processEmailEventsForAllStores() {
58
+
59
+ $stores = Mage::getModel('core/store')->getCollection();
60
+
61
+ foreach($stores as $store) {
62
+ if($store->getConfig('mailgun/events/store')) {
63
+ $this->processEmailEventsForSingleStore($store);
64
+ }
65
+ }
66
+ }
67
+
68
+ public function processEmailEventsForSingleStore(Mage_Core_Model_Store $store) {
69
+
70
+ if($store->getConfig('mailgun/events/store')) {
71
+
72
+ $data = array(
73
+ 'end' => date("r", time() - 86400),
74
+ 'tags' => $store->getConfig('mailgun/general/tag')
75
+ );
76
+
77
+ $mailgunEvents = $this->mailgunRequest(
78
+ 'events',
79
+ $store->getConfig('mailgun/general/domain'),
80
+ $store->getConfig('mailgun/general/key'),
81
+ $data
82
+ );
83
+
84
+ $events = $mailgunEvents->items;
85
+
86
+ while (sizeof($mailgunEvents->items) > 0) {
87
+ $mailgunEvents = $this->mailgunRequest(
88
+ 'events',
89
+ $store->getConfig('mailgun/general/domain'),
90
+ $store->getConfig('mailgun/general/key'),
91
+ $data,
92
+ Zend_Http_Client::GET,
93
+ $mailgunEvents->paging->next
94
+ );
95
+
96
+ $events = array_merge($events, $mailgunEvents->items);
97
+ }
98
+
99
+ $this->storeEvents($events);
100
+ }
101
+ }
102
+
103
+ public function storeEvents($events) {
104
+ foreach($events as $mailgunEvent) {
105
+ $email = Mage::getModel('freelunchlabs_mailgun/email')->loadByMailgunIdAndRecipient($mailgunEvent->message->headers->{'message-id'}, $mailgunEvent->recipient);
106
+
107
+ if($email->getId()) {
108
+ $event = Mage::getModel('freelunchlabs_mailgun/event')->loadByTimestampAndEmailId($mailgunEvent->timestamp, $email->getId());
109
+
110
+ if(!$event->getId()) {
111
+ $event->setEmailId($email->getId());
112
+ $event->setEventType($mailgunEvent->event);
113
+ $event->setTimestamp($mailgunEvent->timestamp);
114
+ $event->save();
115
+ }
116
+ }
117
+ }
118
+ }
119
+
120
+ }
app/code/community/FreeLunchLabs/MailGun/Model/Messagebuilder.php ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Messagebuilder extends Varien_Object {
4
+
5
+ const API_USER = "api";
6
+ const SDK_USER_AGENT = "freelunchlabs_magento_extension";
7
+ const RECIPIENT_COUNT_LIMIT = 1000;
8
+ const CAMPAIGN_ID_LIMIT = 3;
9
+ const TAG_LIMIT = 3;
10
+ const DEFAULT_TIME_ZONE = "UTC";
11
+
12
+ //Common Exception Messages
13
+ const EXCEPTION_INVALID_CREDENTIALS = "Your credentials are incorrect.";
14
+ const EXCEPTION_GENERIC_HTTP_ERROR = "An HTTP Error has occurred! Check your network connection and try again.";
15
+ const EXCEPTION_MISSING_REQUIRED_PARAMETERS = "The parameters passed to the API were invalid. Check your inputs!";
16
+ const EXCEPTION_MISSING_ENDPOINT = "The endpoint you've tried to access does not exist. Check your URL.";
17
+ const TOO_MANY_RECIPIENTS = "You've exceeded the maximum recipient count (1,000) on the to field with autosend disabled.";
18
+ const INVALID_PARAMETER_NON_ARRAY = "The parameter you've passed in position 2 must be an array.";
19
+ const INVALID_PARAMETER_ATTACHMENT = "Attachments must be passed with an \"@\" preceding the file path. Web resources not supported.";
20
+ const INVALID_PARAMETER_INLINE = "Inline images must be passed with an \"@\" preceding the file path. Web resources not supported.";
21
+ const TOO_MANY_PARAMETERS_CAMPAIGNS = "You've exceeded the maximum (3) campaigns for a single message.";
22
+ const TOO_MANY_PARAMETERS_TAGS = "You've exceeded the maximum (3) tags for a single message.";
23
+ const TOO_MANY_PARAMETERS_RECIPIENT = "You've exceeded the maximum recipient count (1,000) on the to field with autosend disabled.";
24
+
25
+ protected $message = array();
26
+ protected $variables = array();
27
+ protected $files = array();
28
+ protected $counters = array('recipients' => array('to' => 0,
29
+ 'cc' => 0,
30
+ 'bcc' => 0),
31
+ 'attributes' => array('attachment' => 0,
32
+ 'campaign_id' => 0,
33
+ 'custom_option' => 0,
34
+ 'tag' => 0)
35
+ );
36
+
37
+ protected function safeGet($params, $key, $default) {
38
+ if (array_key_exists($key, $params)) {
39
+ return $params[$key];
40
+ }
41
+ return $default;
42
+ }
43
+
44
+ protected function getFullName($params) {
45
+ if (array_key_exists("first", $params)) {
46
+ $first = $this->safeGet($params, "first", "");
47
+ $last = $this->safeGet($params, "last", "");
48
+ return trim("$first $last");
49
+ }
50
+ return $this->safeGet($params, "full_name", "");
51
+ }
52
+
53
+ protected function parseAddress($address, $variables) {
54
+ if (!is_array($variables)) {
55
+ return $address;
56
+ }
57
+ $fullName = $this->getFullName($variables);
58
+ if ($fullName != null) {
59
+ return "'$fullName' <$address>";
60
+ }
61
+ return $address;
62
+ }
63
+
64
+ protected function addRecipient($headerName, $address, $variables) {
65
+ $compiledAddress = $this->parseAddress($address, $variables);
66
+
67
+ if (isset($this->message[$headerName])) {
68
+ array_push($this->message[$headerName], $compiledAddress);
69
+ } elseif ($headerName == "h:reply-to") {
70
+ $this->message[$headerName] = $compiledAddress;
71
+ } else {
72
+ $this->message[$headerName] = array($compiledAddress);
73
+ }
74
+ if (array_key_exists($headerName, $this->counters['recipients'])) {
75
+ $this->counters['recipients'][$headerName] += 1;
76
+ }
77
+ }
78
+
79
+ public function addToRecipient($address, $variables = null) {
80
+ if ($this->counters['recipients']['to'] > self::RECIPIENT_COUNT_LIMIT) {
81
+ throw new FreeLunchLabs_MailGun_Model_Exceptions_TooManyParameters(TOO_MANY_PARAMETERS_RECIPIENT);
82
+ }
83
+ $this->addRecipient("to", $address, $variables);
84
+ return end($this->message['to']);
85
+ }
86
+
87
+ public function addCcRecipient($address, $variables = null) {
88
+ if ($this->counters['recipients']['cc'] > self::RECIPIENT_COUNT_LIMIT) {
89
+ throw new FreeLunchLabs_MailGun_Model_Exceptions_TooManyParameters(TOO_MANY_PARAMETERS_RECIPIENT);
90
+ }
91
+ $this->addRecipient("cc", $address, $variables);
92
+ return end($this->message['cc']);
93
+ }
94
+
95
+ public function addBccRecipient($address, $variables = null) {
96
+ if ($this->counters['recipients']['bcc'] > self::RECIPIENT_COUNT_LIMIT) {
97
+ throw new FreeLunchLabs_MailGun_Model_Exceptions_TooManyParameters(TOO_MANY_PARAMETERS_RECIPIENT);
98
+ }
99
+ $this->addRecipient("bcc", $address, $variables);
100
+ return end($this->message['bcc']);
101
+ }
102
+
103
+ public function setFromAddress($address, $variables = null) {
104
+ $this->addRecipient("from", $address, $variables);
105
+ return $this->message['from'];
106
+ }
107
+
108
+ public function setReplyToAddress($address, $variables = null) {
109
+ $this->addRecipient("h:reply-to", $address, $variables);
110
+ return $this->message['h:reply-to'];
111
+ }
112
+
113
+ public function setSubject($subject = NULL) {
114
+ if ($subject == NULL || $subject == "") {
115
+ $subject = " ";
116
+ }
117
+ $this->message['subject'] = $subject;
118
+ return $this->message['subject'];
119
+ }
120
+
121
+ public function getSubject() {
122
+ return $this->message['subject'];
123
+ }
124
+
125
+ public function addCustomHeader($headerName, $headerData) {
126
+ if (!preg_match("/^h:/i", $headerName)) {
127
+ $headerName = "h:" . $headerName;
128
+ }
129
+ $this->message[$headerName] = array($headerData);
130
+ return $this->message[$headerName];
131
+ }
132
+
133
+ public function setTextBody($textBody) {
134
+ if ($textBody == NULL || $textBody == "") {
135
+ $textBody = " ";
136
+ }
137
+ $this->message['text'] = $textBody;
138
+ return $this->message['text'];
139
+ }
140
+
141
+ public function setHtmlBody($htmlBody) {
142
+ if ($htmlBody == NULL || $htmlBody == "") {
143
+ $htmlBody = " ";
144
+ }
145
+ $this->message['html'] = $htmlBody;
146
+ return $this->message['html'];
147
+ }
148
+
149
+ public function getHtmlBody() {
150
+ return $this->message['html'];
151
+ }
152
+
153
+ public function addAttachment($attachmentPath, $attachmentName = null) {
154
+ if (preg_match("/^@/", $attachmentPath)) {
155
+ if (isset($this->files["attachment"])) {
156
+ $attachment = array('filePath' => $attachmentPath,
157
+ 'remoteName' => $attachmentName);
158
+ array_push($this->files["attachment"], $attachment);
159
+ } else {
160
+ $this->files["attachment"] = array(array('filePath' => $attachmentPath,
161
+ 'remoteName' => $attachmentName));
162
+ }
163
+ return true;
164
+ } else {
165
+ throw new FreeLunchLabs_MailGun_Model_Exceptions_InvalidParameter(self::INVALID_PARAMETER_ATTACHMENT);
166
+ }
167
+ }
168
+
169
+ public function addInlineImage($inlineImagePath, $inlineImageName = null) {
170
+ if (preg_match("/^@/", $inlineImagePath)) {
171
+ if (isset($this->files['inline'])) {
172
+ $inlineAttachment = array('filePath' => $inlineImagePath,
173
+ 'remoteName' => $inlineImageName);
174
+ array_push($this->files['inline'], $inlineAttachment);
175
+ } else {
176
+ $this->files['inline'] = array(array('filePath' => $inlineImagePath,
177
+ 'remoteName' => $inlineImageName));
178
+ }
179
+ return true;
180
+ } else {
181
+ throw new FreeLunchLabs_MailGun_Model_Exceptions_InvalidParameter(self::INVALID_PARAMETER_INLINE);
182
+ }
183
+ }
184
+
185
+ public function setTestMode($testMode) {
186
+ if (filter_var($testMode, self::FILTER_VALIDATE_BOOLEAN)) {
187
+ $testMode = "yes";
188
+ } else {
189
+ $testMode = "no";
190
+ }
191
+ $this->message['o:testmode'] = $testMode;
192
+ return $this->message['o:testmode'];
193
+ }
194
+
195
+ public function addCampaignId($campaignId) {
196
+ if ($this->counters['attributes']['campaign_id'] < self::CAMPAIGN_ID_LIMIT) {
197
+ if (isset($this->message['o:campaign'])) {
198
+ array_push($this->message['o:campaign'], $campaignId);
199
+ } else {
200
+ $this->message['o:campaign'] = array($campaignId);
201
+ }
202
+ $this->counters['attributes']['campaign_id'] += 1;
203
+ return $this->message['o:campaign'];
204
+ } else {
205
+ throw new FreeLunchLabs_MailGun_Model_Exceptions_TooManyParameters(self::TOO_MANY_PARAMETERS_CAMPAIGNS);
206
+ }
207
+ }
208
+
209
+ public function addTag($tag) {
210
+ if ($this->counters['attributes']['tag'] < self::TAG_LIMIT) {
211
+ if (isset($this->message['o:tag'])) {
212
+ array_push($this->message['o:tag'], $tag);
213
+ } else {
214
+ $this->message['o:tag'] = array($tag);
215
+ }
216
+ $this->counters['attributes']['tag'] += 1;
217
+ return $this->message['o:tag'];
218
+ } else {
219
+ throw new FreeLunchLabs_MailGun_Model_Exceptions_TooManyParameters(self::TOO_MANY_PARAMETERS_TAGS);
220
+ }
221
+ }
222
+
223
+ public function setDkim($enabled) {
224
+ if (filter_var($enabled, FILTER_VALIDATE_BOOLEAN)) {
225
+ $enabled = "yes";
226
+ } else {
227
+ $enabled = "no";
228
+ }
229
+ $this->message["o:dkim"] = $enabled;
230
+ return $this->message["o:dkim"];
231
+ }
232
+
233
+ public function setOpenTracking($enabled) {
234
+ if (filter_var($enabled, FILTER_VALIDATE_BOOLEAN)) {
235
+ $enabled = "yes";
236
+ } else {
237
+ $enabled = "no";
238
+ }
239
+ $this->message['o:tracking-opens'] = $enabled;
240
+ return $this->message['o:tracking-opens'];
241
+ }
242
+
243
+ public function setClickTracking($enabled) {
244
+ if (filter_var($enabled, FILTER_VALIDATE_BOOLEAN)) {
245
+ $enabled = "yes";
246
+ } elseif ($enabled == "html") {
247
+ $enabled = "html";
248
+ } else {
249
+ $enabled = "no";
250
+ }
251
+ $this->message['o:tracking-clicks'] = $enabled;
252
+ return $this->message['o:tracking-clicks'];
253
+ }
254
+
255
+ public function setDeliveryTime($timeDate, $timeZone = NULL) {
256
+ if (isset($timeZone)) {
257
+ $timeZoneObj = new DateTimeZone("$timeZone");
258
+ } else {
259
+ $timeZoneObj = new DateTimeZone(self::DEFAULT_TIME_ZONE);
260
+ }
261
+
262
+ $dateTimeObj = new DateTime($timeDate, $timeZoneObj);
263
+ $formattedTimeDate = $dateTimeObj->format(DateTime::RFC2822);
264
+ $this->message['o:deliverytime'] = $formattedTimeDate;
265
+ return $this->message['o:deliverytime'];
266
+ }
267
+
268
+ public function addCustomData($customName, $data) {
269
+ if (is_array($data)) {
270
+ $jsonArray = json_encode($data);
271
+ $this->message['v:' . $customName] = $jsonArray;
272
+ return $this->message['v:' . $customName];
273
+ } else {
274
+ throw new FreeLunchLabs_MailGun_Model_Exceptions_InvalidParameter(self::INVALID_PARAMETER_NON_ARRAY);
275
+ }
276
+ }
277
+
278
+ public function addCustomParameter($parameterName, $data) {
279
+ if (isset($this->message[$parameterName])) {
280
+ array_push($this->message[$parameterName], $data);
281
+ return $this->message[$parameterName];
282
+ } else {
283
+ $this->message[$parameterName] = array($data);
284
+ return $this->message[$parameterName];
285
+ }
286
+ }
287
+
288
+ public function getMessage() {
289
+ return $this->message;
290
+ }
291
+
292
+ public function getFiles() {
293
+ return $this->files;
294
+ }
295
+
296
+ }
app/code/community/FreeLunchLabs/MailGun/Model/Resource/Email.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Resource_Email extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ protected function _construct()
6
+ {
7
+ $this->_init('freelunchlabs_mailgun/email', 'id');
8
+ }
9
+
10
+ public function deleteEmailTrackingLogs($days = false) {
11
+ if($days) {
12
+ $daysPrior = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time() - (86400 * $days)));
13
+ $where = " WHERE date_sent < '{$daysPrior}'";
14
+ } else {
15
+ $where = "";
16
+ }
17
+
18
+ $query = "DELETE FROM {$this->getMainTable()}" . $where;
19
+
20
+ Mage::getSingleton('core/resource')
21
+ ->getConnection('core_write')
22
+ ->query($query);
23
+
24
+ }
25
+
26
+ }
app/code/community/FreeLunchLabs/MailGun/Model/Resource/Email/Collection.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Resource_Email_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+
9
+ $this->_init('freelunchlabs_mailgun/email');
10
+ }
11
+
12
+ public function getGridCollection() {
13
+ //Fields
14
+ $this->addFieldToSelect('id');
15
+ $this->addFieldToSelect('subject');
16
+ $this->addFieldToSelect('email_address');
17
+ $this->addFieldToSelect('mailgun_id');
18
+ $this->addFieldToSelect('date_sent');
19
+ $this->addFieldToSelect('customer_id');
20
+
21
+ //Get latest status
22
+ $this->getSelect()->joinLeft(
23
+ array('me1' => Mage::getResourceModel('freelunchlabs_mailgun/event')->getMainTable()),
24
+ 'main_table.id = me1.email_id',
25
+ 'event_type as current_status'
26
+ );
27
+
28
+ $this->getSelect()->joinLeft(
29
+ array('me2' => Mage::getResourceModel('freelunchlabs_mailgun/event')->getMainTable()),
30
+ '(main_table.id = me2.email_id AND (me1.timestamp < me2.timestamp OR me1.timestamp = me2.timestamp AND me1.id < me2.id))',
31
+ false
32
+ );
33
+
34
+ $this->getSelect()->where('me2.id IS NULL');
35
+
36
+ return $this;
37
+ }
38
+ }
app/code/community/FreeLunchLabs/MailGun/Model/Resource/Event.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Resource_Event extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ protected function _construct()
6
+ {
7
+ $this->_init('freelunchlabs_mailgun/event', 'id');
8
+ }
9
+
10
+ }
app/code/community/FreeLunchLabs/MailGun/Model/Resource/Event/Collection.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Model_Resource_Event_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+
9
+ $this->_init('freelunchlabs_mailgun/event');
10
+ }
11
+ }
app/code/community/FreeLunchLabs/MailGun/controllers/Adminhtml/EmailtrackingController.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FreeLunchLabs_MailGun_Adminhtml_EmailtrackingController extends Mage_Adminhtml_Controller_Action {
4
+
5
+ protected function _initCustomer($idFieldName = 'id')
6
+ {
7
+ $this->_title($this->__('Customers'))->_title($this->__('Manage Customers'));
8
+
9
+ $customerId = (int) $this->getRequest()->getParam($idFieldName);
10
+ $customer = Mage::getModel('customer/customer');
11
+
12
+ if ($customerId) {
13
+ $customer->load($customerId);
14
+ }
15
+
16
+ Mage::register('current_customer', $customer);
17
+ return $this;
18
+ }
19
+
20
+ protected function _initEmail($idFieldName = 'id') {
21
+ $emailId = (int) $this->getRequest()->getParam($idFieldName);
22
+ $email = Mage::getModel('freelunchlabs_mailgun/email');
23
+
24
+ if ($emailId) {
25
+ $email->load($emailId);
26
+ }
27
+
28
+ Mage::register('current_email', $email);
29
+ return $this;
30
+ }
31
+
32
+ public function emailGridAction()
33
+ {
34
+ $this->_initCustomer();
35
+ $this->loadLayout();
36
+ $gridBlock = $this->getLayout()->createBlock('freelunchlabs_mailgun/adminhtml_customer_email');
37
+
38
+ $this->getResponse()->setBody($gridBlock->getGridHtml());
39
+ }
40
+
41
+ public function indexAction() {
42
+ $this->_title($this->__('System'))->_title($this->__('Email Tracking'));
43
+
44
+ $this->loadLayout();
45
+ $this->_setActiveMenu('customer');
46
+ $this->renderLayout();
47
+ }
48
+
49
+ public function emailDetailAction() {
50
+ $this->_title($this->__('System'))->_title($this->__('Email Tracking - Detail'));
51
+
52
+ $this->_initEmail();
53
+
54
+ $this->loadLayout();
55
+ $this->_setActiveMenu('customer');
56
+ $this->renderLayout();
57
+ }
58
+
59
+ public function getEmailEventsAction() {
60
+ Mage::getModel('freelunchlabs_mailgun/mailgun')->processEmailEventsForAllStores();
61
+
62
+ $this->_getSession()->addSuccess(
63
+ Mage::helper('adminhtml')->__('Past 24 hours of email events fetched.')
64
+ );
65
+
66
+ $this->_redirect('*/*');
67
+ }
68
+
69
+ public function emailViewAction() {
70
+ $this->_title($this->__('System'))->_title($this->__('Email Tracking - Detail - Email Body'));
71
+ $this->_initEmail();
72
+
73
+ $this->getResponse()->setBody(Mage::registry('current_email')->getBody());
74
+ }
75
+
76
+ public function deleteEmailTrackingLogsDaysAction() {
77
+ Mage::getModel('freelunchlabs_mailgun/email')->deleteEmailTrackingLogsDays();
78
+
79
+ $this->_getSession()->addSuccess(
80
+ Mage::helper('adminhtml')->__('Email records older than ' . Mage::getStoreConfig('mailgun/events/days') . ' days were deleted.')
81
+ );
82
+
83
+ $this->_redirect('*/*');
84
+ }
85
+
86
+ public function deleteEmailTrackingLogsAction() {
87
+ Mage::getModel('freelunchlabs_mailgun/email')->deleteEmailTrackingLogs();
88
+
89
+ $this->_getSession()->addSuccess(
90
+ Mage::helper('adminhtml')->__('All Email Records Were Deleted.')
91
+ );
92
+
93
+ $this->_redirect('*/*');
94
+ }
95
+
96
+ }
app/code/community/FreeLunchLabs/MailGun/etc/config.xml ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <FreeLunchLabs_MailGun>
5
+ <version>1.0.0</version>
6
+ </FreeLunchLabs_MailGun>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <freelunchlabs_mailgun>
11
+ <class>FreeLunchLabs_MailGun_Model</class>
12
+ <resourceModel>freelunchlabs_mailgun_resource</resourceModel>
13
+ </freelunchlabs_mailgun>
14
+ <core>
15
+ <rewrite>
16
+ <email_template>FreeLunchLabs_MailGun_Model_Email_Template</email_template>
17
+ </rewrite>
18
+ </core>
19
+ <freelunchlabs_mailgun_resource>
20
+ <class>FreeLunchLabs_MailGun_Model_Resource</class>
21
+ <entities>
22
+ <email>
23
+ <table>mailgun_email_tracking</table>
24
+ </email>
25
+ <event>
26
+ <table>mailgun_email_tracking_event</table>
27
+ </event>
28
+ </entities>
29
+ </freelunchlabs_mailgun_resource>
30
+ </models>
31
+ <resources>
32
+ <mailgun_setup>
33
+ <setup>
34
+ <module>FreeLunchLabs_MailGun</module>
35
+ </setup>
36
+ <connection>
37
+ <use>core_setup</use>
38
+ </connection>
39
+ </mailgun_setup>
40
+ <mailgun_write>
41
+ <connection>
42
+ <use>core_write</use>
43
+ </connection>
44
+ </mailgun_write>
45
+ <mailgun_read>
46
+ <connection>
47
+ <use>core_read</use>
48
+ </connection>
49
+ </mailgun_read>
50
+ </resources>
51
+ <helpers>
52
+ <mailgun>
53
+ <class>FreeLunchLabs_MailGun_Helper</class>
54
+ </mailgun>
55
+ </helpers>
56
+ <blocks>
57
+ <freelunchlabs_mailgun>
58
+ <class>FreeLunchLabs_MailGun_Block</class>
59
+ </freelunchlabs_mailgun>
60
+ </blocks>
61
+ </global>
62
+ <admin>
63
+ <routers>
64
+ <adminhtml>
65
+ <args>
66
+ <modules>
67
+ <freelunchlabs_mailgun before="Mage_Adminhtml">FreeLunchLabs_MailGun_Adminhtml</freelunchlabs_mailgun>
68
+ </modules>
69
+ </args>
70
+ </adminhtml>
71
+ </routers>
72
+ </admin>
73
+ <adminhtml>
74
+ <menu>
75
+ <customer>
76
+ <children>
77
+ <cloudfront translate="title" module="mailgun">
78
+ <title>Email Tracking</title>
79
+ <sort_order>9999</sort_order>
80
+ <action>adminhtml/emailtracking</action>
81
+ </cloudfront>
82
+ </children>
83
+ </customer>
84
+ </menu>
85
+ <acl>
86
+ <resources>
87
+ <admin>
88
+ <children>
89
+ <system>
90
+ <children>
91
+ <config>
92
+ <children>
93
+ <mailgun translate="title" module="mailgun">
94
+ <title>MailGun Configuration</title>
95
+ <sort_order>50</sort_order>
96
+ </mailgun>
97
+ </children>
98
+ </config>
99
+ <emailtracking>
100
+ <title>Email Tracking</title>
101
+ <sort_order>70</sort_order>
102
+ </emailtracking>
103
+ </children>
104
+ </system>
105
+ </children>
106
+ </admin>
107
+ </resources>
108
+ </acl>
109
+ <layout>
110
+ <updates>
111
+ <mailgun>
112
+ <file>mailgun.xml</file>
113
+ </mailgun>
114
+ </updates>
115
+ </layout>
116
+ </adminhtml>
117
+ <default>
118
+ <mailgun>
119
+ <general>
120
+ <active>0</active>
121
+ <tag>magento-store</tag>
122
+ </general>
123
+ <events>
124
+ <store>1</store>
125
+ <days>30</days>
126
+ <clicks>1</clicks>
127
+ <opens>1</opens>
128
+ </events>
129
+ </mailgun>
130
+ </default>
131
+ <crontab>
132
+ <jobs>
133
+ <freelunchlabs_purgelogs>
134
+ <schedule>
135
+ <cron_expr>0,15,30,45 * * * *</cron_expr>
136
+ </schedule>
137
+ <run>
138
+ <model>freelunchlabs_mailgun/email::deleteEmailTrackingLogsDays</model>
139
+ </run>
140
+ </freelunchlabs_purgelogs>
141
+ <freelunchlabs_processevents>
142
+ <schedule>
143
+ <cron_expr>0,15,30,45 * * * *</cron_expr>
144
+ </schedule>
145
+ <run>
146
+ <model>freelunchlabs_mailgun/mailgun::processEmailEventsForAllStores</model>
147
+ </run>
148
+ </freelunchlabs_processevents>
149
+ </jobs>
150
+ </crontab>
151
+ </config>
app/code/community/FreeLunchLabs/MailGun/etc/system.xml ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <mailgun translate="label" module="mailgun">
5
+ <class>separator-top</class>
6
+ <label>MailGun Configuration</label>
7
+ <tab>general</tab>
8
+ <sort_order>110</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <general translate="label comment">
14
+ <label>MailGun Configuration</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>1</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>0</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <active translate="label comment">
22
+ <label>Enabled MailGun For Sending Emails</label>
23
+ <frontend_type>select</frontend_type>
24
+ <source_model>adminhtml/system_config_source_yesno</source_model>
25
+ <sort_order>1</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ </active>
30
+ <key translate="label comment">
31
+ <label>MailGun API Key</label>
32
+ <frontend_type>password</frontend_type>
33
+ <sort_order>3</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>1</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ <comment>Your MailGun API Key</comment>
38
+ </key>
39
+ <domain translate="label comment">
40
+ <label>Sending Domain</label>
41
+ <frontend_type>text</frontend_type>
42
+ <sort_order>4</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ <comment>Your verified sending domain. For example, "example.com", "email.example.com"</comment>
47
+ </domain>
48
+ <tag translate="label comment">
49
+ <label>Email Tag</label>
50
+ <frontend_type>text</frontend_type>
51
+ <sort_order>5</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>1</show_in_store>
55
+ <comment>For Administrative purposes only. This tag is used for filtering emails in MailGun.</comment>
56
+ </tag>
57
+ </fields>
58
+ </general>
59
+ <events translate="label">
60
+ <label>Email Tracking</label>
61
+ <frontend_type>text</frontend_type>
62
+ <sort_order>2</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ <fields>
67
+ <store translate="label comment">
68
+ <label>Track All Emails</label>
69
+ <frontend_type>select</frontend_type>
70
+ <source_model>adminhtml/system_config_source_yesno</source_model>
71
+ <sort_order>1</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>1</show_in_store>
75
+ <comment>Keep a record of all transactional emails sent.</comment>
76
+ </store>
77
+ <days translate="label comment">
78
+ <label>Days To Save Email Records</label>
79
+ <frontend_type>text</frontend_type>
80
+ <sort_order>2</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>0</show_in_website>
83
+ <show_in_store>0</show_in_store>
84
+ <comment>Days to save email records. Leave blank for indefinitely.</comment>
85
+ </days>
86
+ <clicks translate="label comment">
87
+ <label>Enabled Click Tracking</label>
88
+ <frontend_type>select</frontend_type>
89
+ <source_model>adminhtml/system_config_source_yesno</source_model>
90
+ <sort_order>3</sort_order>
91
+ <show_in_default>1</show_in_default>
92
+ <show_in_website>1</show_in_website>
93
+ <show_in_store >1</show_in_store>
94
+ <comment>Keep track of every time a recipient clicks on links in your messages. Links will be overwritten and pointed to MailGun servers so they can track clicks.</comment>
95
+ </clicks>
96
+ <opens translate="label comment">
97
+ <label>Enabled Open Tracking</label>
98
+ <frontend_type>select</frontend_type>
99
+ <source_model>adminhtml/system_config_source_yesno</source_model>
100
+ <sort_order>4</sort_order>
101
+ <show_in_default>1</show_in_default>
102
+ <show_in_website>1</show_in_website>
103
+ <show_in_store>1</show_in_store>
104
+ <comment>Keep track of every time a recipient opens your messages. Opens are tracked by including a transparent .png file in you email.</comment>
105
+ </opens>
106
+ </fields>
107
+ </events>
108
+ </groups>
109
+ </mailgun>
110
+ </sections>
111
+ </config>
app/code/community/FreeLunchLabs/MailGun/sql/mailgun_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ SET FOREIGN_KEY_CHECKS = 0;
10
+ DROP TABLE IF EXISTS {$this->getTable('freelunchlabs_mailgun/email')};
11
+ DROP TABLE IF EXISTS {$this->getTable('freelunchlabs_mailgun/event')};
12
+ SET FOREIGN_KEY_CHECKS = 1;
13
+
14
+ -- DROP TABLE IF EXISTS {$this->getTable('freelunchlabs_mailgun/email')};
15
+ CREATE TABLE {$this->getTable('freelunchlabs_mailgun/email')} (
16
+ `id` int(11) unsigned NOT NULL auto_increment,
17
+ `customer_id` int(11) NULL,
18
+ `mailgun_id` varchar(255) NOT NULL default '',
19
+ `email_address` varchar(255) NOT NULL default '',
20
+ `subject` text,
21
+ `body` text,
22
+ `date_sent` timestamp NOT NULL,
23
+ PRIMARY KEY (`id`)
24
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
25
+
26
+ -- DROP TABLE IF EXISTS {$this->getTable('freelunchlabs_mailgun/event')};
27
+ CREATE TABLE {$this->getTable('freelunchlabs_mailgun/event')} (
28
+ `id` int(11) unsigned NOT NULL auto_increment,
29
+ `email_id` int(11) unsigned NULL,
30
+ `event_type` varchar(255) NOT NULL default '',
31
+ `timestamp` varchar(255),
32
+ PRIMARY KEY (`id`),
33
+ CONSTRAINT `fk_mailgun_event` FOREIGN KEY (`email_id`) REFERENCES `{$this->getTable('freelunchlabs_mailgun/email')}` (`id`) ON DELETE CASCADE
34
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
35
+
36
+ ");
37
+
38
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/mailgun.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_customer_edit>
4
+ <reference name="customer_edit_tabs">
5
+ <action method="addTab">
6
+ <name>customer_tab_mailgun</name>
7
+ <block>freelunchlabs_mailgun/adminhtml_customer_tab_mailgun</block>
8
+ </action>
9
+ </reference>
10
+ </adminhtml_customer_edit>
11
+ <adminhtml_emailtracking_index>
12
+ <reference name="content">
13
+ <block type="freelunchlabs_mailgun/adminhtml_emailtracking" name="emailtracking" template="mailgun/globalemailgrid.phtml"></block>
14
+ </reference>
15
+ </adminhtml_emailtracking_index>
16
+ <adminhtml_emailtracking_emaildetail>
17
+ <reference name="content">
18
+ <block type="freelunchlabs_mailgun/adminhtml_emailtracking" name="emailtracking" template="mailgun/emaildetail.phtml"></block>
19
+ </reference>
20
+ </adminhtml_emailtracking_emaildetail>
21
+ </layout>
app/design/adminhtml/default/default/template/mailgun/customer/tab/tab.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <?php echo $this->getGrid(); ?>
app/design/adminhtml/default/default/template/mailgun/emaildetail.phtml ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_emailDetail = $this->getEmailDetail(); ?>
2
+ <div class="content-header">
3
+ <table cellspacing="0">
4
+ <tr>
5
+ <td>
6
+ <h3><?php echo Mage::helper('adminhtml')->__('Email Details') ?></h3>
7
+ </td>
8
+ <td class="form-buttons">
9
+ <?php echo $this->getBackButtonHtml(); ?>
10
+ <?php echo $this->getViewEmailBodyButtonHtml($_emailDetail->getId()); ?>
11
+ </td>
12
+ </tr>
13
+ </table>
14
+ </div>
15
+ <div class="box-left">
16
+ <div class="entry-edit">
17
+ <div class="entry-edit-head">
18
+ <h4 class="icon-head head-account"><?php echo Mage::helper('adminhtml')->__('Email Information') ?></h4>
19
+ </div>
20
+ <div class="fieldset">
21
+ <table cellspacing="0" class="form-list">
22
+ <tbody>
23
+ <tr>
24
+ <td class="label"><label><?php echo Mage::helper('adminhtml')->__('Date Sent') ?></label></td>
25
+ <td class="value"><strong><?php echo Mage::helper('core')->formatDate($_emailDetail->getDateSent(), 'full', true); ?></strong></td>
26
+ </tr>
27
+ <tr>
28
+ <td class="label"><label><?php echo Mage::helper('adminhtml')->__('Subject') ?></label></td>
29
+ <td class="value"><strong><?php echo $_emailDetail->getSubject(); ?></strong></td>
30
+ </tr>
31
+ <tr>
32
+ <td class="label"><label><?php echo Mage::helper('adminhtml')->__('Mailgun ID') ?></label></td>
33
+ <td class="value"><strong><?php echo $_emailDetail->getMailgunId(); ?></strong></td>
34
+ </tr>
35
+ <tr>
36
+ <td class="label"><label><?php echo Mage::helper('adminhtml')->__('Recipient') ?></label></td>
37
+ <td class="value"><strong><?php echo $_emailDetail->getEmailAddress(); ?></strong></td>
38
+ </tr>
39
+ </tbody>
40
+ </table>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ <div class="box-right">
45
+ <div class="entry-edit">
46
+ <div class="entry-edit-head">
47
+ <h4 class="icon-head head-account"><?php echo Mage::helper('adminhtml')->__('Customer Information') ?></h4>
48
+ </div>
49
+ <div class="fieldset">
50
+ <?php if($_emailDetail->getCustomer()): ?>
51
+ <table cellspacing="0" class="form-list">
52
+ <tbody>
53
+ <tr>
54
+ <td class="label"><label><?php echo Mage::helper('adminhtml')->__('Customer') ?></label></td>
55
+ <td class="value">
56
+ <a href="<?php echo $this->getEditCustomerUrl($_emailDetail->getCustomer()->getId()); ?>" title="Edit Customer">
57
+ <strong><?php echo $_emailDetail->getCustomer()->getName(); ?></strong>
58
+ </a>
59
+ </td>
60
+ </tr>
61
+ <tr>
62
+ <td class="label"><label><?php echo Mage::helper('adminhtml')->__('Store') ?></label></td>
63
+ <td class="value"><strong><?php echo $_emailDetail->getCustomer()->getStore()->getName(); ?></strong></td>
64
+ </tr>
65
+ <tr>
66
+ <td class="label"><label><?php echo Mage::helper('adminhtml')->__('Customer Group') ?></label></td>
67
+ <td class="value"><strong><?php echo $this->getCustomerGroupName($_emailDetail->getCustomer()->getGroupId()); ?></strong></td>
68
+ </tr>
69
+ <tr>
70
+ <td class="label"><label><?php echo Mage::helper('adminhtml')->__('Customer Since') ?></label></td>
71
+ <td class="value"><strong><?php echo $this->formatCustomerCreateDate($_emailDetail->getCustomer()->getCreatedAt()); ?></strong></td>
72
+ </tr>
73
+ </tbody>
74
+ </table>
75
+ <?php else: ?>
76
+ <p>No Customer Data Available.</p>
77
+ <?php endif; ?>
78
+ </div>
79
+ </div>
80
+ </div>
81
+ <div class="content-header">
82
+ <table cellspacing="0">
83
+ <tr>
84
+ <td>
85
+ <h3><?php echo Mage::helper('adminhtml')->__('Email Events') ?></h3>
86
+ </td>
87
+ </tr>
88
+ </table>
89
+ </div>
90
+ <?php echo $this->getLayout()->createBlock('freelunchlabs_mailgun/adminhtml_event_container')->getGridHtml(); ?>
app/design/adminhtml/default/default/template/mailgun/globalemailgrid.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0">
3
+ <tr>
4
+ <td>
5
+ <h3><?php echo Mage::helper('adminhtml')->__('Email Activity') ?></h3>
6
+ </td>
7
+ <td class="form-buttons">
8
+ <?php echo $this->getFetch24HoursOfEmailActivityButton(); ?>
9
+ <?php echo $this->getDeleteEmailTrackingLogsDaysButton(); ?>
10
+ <?php echo $this->getDeleteAllEmailTrackingLogsButton(); ?>
11
+ </td>
12
+ </tr>
13
+ </table>
14
+ </div>
15
+ <?php echo $this->getLayout()->createBlock('freelunchlabs_mailgun/adminhtml_global_container')->getGridHtml(); ?>
app/etc/modules/FreeLunchLabs_MailGun.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <FreeLunchLabs_MailGun>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </FreeLunchLabs_MailGun>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>FreeLunchLabs_MailGun</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>Massachusetts Institute of Technology License (MITL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Community extension to send all transactional emails via MailGun. Tracks and stores outgoing emails. </summary>
10
+ <description>Community extension to send all transactional emails via MailGun. Uses the MailGun web/rest API so emails are send via HTTP eliminating the need for a SMTP service on the server.&#xD;
11
+ &#xD;
12
+ Keeps track of email events (ie opens, clicks, spam reports...) and formats it into a timeline table that it tied to a customer's records in the Magento Admin.</description>
13
+ <notes>First stable release</notes>
14
+ <authors><author><name>Charles Drew</name><user>freelunchlabs</user><email>info@freelunchlabs.com</email></author></authors>
15
+ <date>2014-10-23</date>
16
+ <time>19:20:13</time>
17
+ <contents><target name="magecommunity"><dir name="FreeLunchLabs"><dir name="MailGun"><dir name="Block"><dir name="Adminhtml"><dir name="Customer"><dir name="Email"><file name="Grid.php" hash="cb7c77bac08eca31fe835eee5e30bbeb"/></dir><file name="Email.php" hash="14c57a6b10ef0553253962ab230b2ce1"/><dir name="Tab"><file name="Mailgun.php" hash="048db6b7f890f3aec7471e1556819260"/></dir></dir><file name="Emailtracking.php" hash="b1d3754829b97e7008625fa39ad9adf6"/><dir name="Event"><file name="Container.php" hash="712cf721b61a7634711922eca6dd5743"/><file name="Grid.php" hash="1c50d4e231eb3fc78271a789896b500b"/><dir name="Renderer"><file name="Timestamp.php" hash="bcee53b40f2936fcf9f20b2aafcb5616"/><file name="Type.php" hash="f353b01f7f86171b2ff3c920e4d3d723"/></dir></dir><dir name="Global"><file name="Container.php" hash="15edc0b922a74082f2652d939cd03061"/><file name="Grid.php" hash="e26caae9e0d91cfb8cc19734ed342b4d"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="063a1cf7646cbf7c99bff0e1ede47177"/></dir><dir name="Model"><dir name="Email"><file name="Template.php" hash="28332f213ca5eb63a8143317c0ad3b93"/></dir><file name="Email.php" hash="120563b544c1313fe9991d292a27ecb1"/><file name="Event.php" hash="b13b9057fc969eb13329f37f33ad75ff"/><dir name="Exceptions"><file name="InvalidParameter.php" hash="8f2484b9abfadf317900cd4fa4a9291a"/><file name="InvalidParameterType.php" hash="0f2c37ff7d3743b121658960627e889c"/><file name="MissingRequiredMIMEParameters.php" hash="64e9466d6027273f9a45a2a41289ed27"/><file name="TooManyParameters.php" hash="bdd51d1d22fcca606a7fff230f3f716e"/></dir><file name="Mailgun.php" hash="da78d7f75fd4fbc1bdb4f81b2259ad6f"/><file name="Messagebuilder.php" hash="d01e64628eae574d0333cc5d562ddf5d"/><dir name="Resource"><dir name="Email"><file name="Collection.php" hash="8750f4d92e14706f9aa43d232e148be0"/></dir><file name="Email.php" hash="4380e6993259ea53fc2b37c4281b8f54"/><dir name="Event"><file name="Collection.php" hash="35bdbf0bcdec4df33f8073fec29afdc1"/></dir><file name="Event.php" hash="e7ac66eb2f30142b5b57acbe46c84a34"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="EmailtrackingController.php" hash="a4c2eb160e733acf9024472a0ef8c1c7"/></dir></dir><dir name="etc"><file name="config.xml" hash="7f1371ef3801a1fa07f6ca09c70d16eb"/><file name="system.xml" hash="8208268e98b32046d34afb7e9b4e6745"/></dir><dir name="sql"><dir name="mailgun_setup"><file name="mysql4-install-1.0.0.php" hash="3429c478be1a072beef83cb6169766b6"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="mailgun.xml" hash="85aed5b6d3aa2ca8934fb98ffa6cb2eb"/></dir><dir name="template"><dir name="mailgun"><dir name="customer"><dir name="tab"><file name="tab.phtml" hash="01bcc905ad74afe78d40114658b69ea0"/></dir></dir><file name="emaildetail.phtml" hash="f9bbfcb29a0ae6fb581ceba2f6682c3f"/><file name="globalemailgrid.phtml" hash="c6331e297cd1645395e7121372ba4ba1"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="FreeLunchLabs_MailGun.xml" hash="f950bcd34fa6d0949074ac5c51375495"/></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies><required><php><min>5.3.0</min><max>5.6.1</max></php></required></dependencies>
20
+ </package>