0

I have been looking through the Core classes in Magento and observed that there seem to be many ways of sending emails through Magento. Also, I could not find a definitive guide on what to choose and when. Here I'll list my findings and would like to have someone help me with c

  1. class Mage_Core_Model_Email_Template
  2. class Mage_Core_Model_Email_Template_Mailer: Looks to be an abstraction of the above class Mage_Core_Model_Email_Template since it creates an instance of the above class in the send() method.
  3. class Mage_Core_Model_Email: Looks to be a completely separate implementation without any relation to any of the above classes.

What should help me decide which of these classes to use? and when? What are the benefits / limitations of using each?

My use case: I am looking to send an email from the admin backend. A report to be sent to the admin of the site of all products that have been flagged by users (flagging functionality has been custom built in the frontend and a listing grid in the backend too. But the admin also wants a daily report)

But, besides this I would also like to know when would each of these classes be used and what would be the considerations taken while making this decision?

Thanks!

  • what you want, immediate or by cron. – Sohel Rana May 22 at 16:10
  • I am looking to send an email from the admin backend. Consider say, a report of all products that have been flagged by users to the admin. Description of the question updated. – yd87 May 22 at 16:13
1

I've seen some complex solutions to this. But in m1 it can actually be done really simply.

$mail = Mage::getModel('core/email')
    ->setToName('Xigen')
    ->setToEmail('dominic@whatever.com')
    ->setSubject('Problem')
    ->setBody('<p>markup<p>')
    ->setFromEmail('customerservices@whatever.co.uk')
    ->setFromName('Customer services\'s')
    ->setType('html');
try {
    $mail->send();
} catch (Exception $e) {
    Mage::throwException($e);
}

I think sometimes simple is best. Clean and easy to read.

This approach means you cant use transactional email templates though. These are the CMS type entries with the smart tags (or whatever magento call them).

Method 3 for the win!

Method 1 gives you the above abilities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.