Add parent to email generated with MailerFactory

I am using MailerFactory to programmatically send emails from a Case.

When the email is sent and the record created, I want to relate the Case to the Email (I have the case id).

There is probably a parameter I can use in the MailerFactory to give the specifics for the emails_beans table to be populated, but I can't find it.

This is the part of my custom function that sends the email:

    if (filter_var($to_addr, FILTER_VALIDATE_EMAIL)){
        $phpMailer = MailerFactory::getSystemDefaultMailer();
        $mailTransmissionProtocol = $phpMailer->getMailTransmissionProtocol();
        $FromEmailIdentity = new EmailIdentity($FromEmailAdd, $FromEmailName);
        $header_array = array(
          'Sender'=>$FromEmailIdentity, //mandatory
        $phpMailer->addRecipientsTo(new EmailIdentity($to_addr, $to_addr));
      }catch(MailerException $me) {
        $message = $me->getMessage();
          "SendGroupEmail: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})"


André Lopes can you help?

  • MailerFactory is only a mailer engine (returns instance of BaseMailer), not an implementation of Email bean, so it has no attributes for relating to a record (parent_type, parent_id).

    So you will need to manage an instance of Email bean and, eventually call the method sendEmail instead.

    Otherwise you would need to instantiate and populate a Email bean as soon as you send the email through MailerFactory. I'm not sure it would be a better approach.


    André Lopes
    Lampada Global
    Skype: andre.lampada