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!

2
  • what you want, immediate or by cron.
    – Sohel Rana
    Commented May 22, 2019 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.
    – YD8877
    Commented May 22, 2019 at 16:13

1 Answer 1

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('[email protected]')
    ->setSubject('Problem')
    ->setBody('<p>markup<p>')
    ->setFromEmail('[email protected]')
    ->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 and acknowledge you have read our privacy policy.

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