Jump to content
thirty bees forum
  • 0

IsTransactional: True header with the new MailTransport based Mail.php class - using legacy swiftmailer


Question

Posted (edited)

Hello

I am using ElasticEmail to send emails from ThirtyBees. I specify that the emails sent by ThirtyBees are transactional emails. This way, people who have unsubscribed my emails (marketing/newsletter emails) still receive transactional emails (order confirmation, etc.). This is done by adding a header to the emails, IsTransactional: True.
More info: https://help.elasticemail.com/en/articles/2419281-what-is-the-difference-between-marketing-and-transactional-email
I pass this header when sending emails from ThirtyBees.

 

Up to TB 1.4

I took Mail.php class, added this line and placed the edited Mail.php class in /override/classes/Mail.php

            /* Send mail */
            $message->setFrom([$from => $fromName]);
            $message->getHeaders()->addTextHeader("IsTransactional", "True");
            $shouldSend = $configuration['PS_MAIL_METHOD'] != static::MAIL_METHOD_NONE;
            $send = $shouldSend ? $swift->send($message) : true;

 

With TB 1.5

Things are changing. Mail.php class now uses MailTransport and an associated module. Here is how I have achieved passing IsTransactional: True header.

1/ In TB admin, install and activate the module: Mail via swiftmailer

Screenshot 2023-03-05 at 15.39.31.png

2/ Configure the module to use PHP's mail() function

Screenshot 2023-03-05 at 15.38.40.png

3/ Edit /modules/tbswiftmailer/src/SwiftMailerTransport.php by adding the last line here:

        $message = Swift_Message::newInstance();
        $message->setSubject($subject);
        $message->setCharset('utf-8');
        $message->setId(static::generateId());
        $message->setFrom($fromAddress->getAddress(), $fromAddress->getName());
        $message->setReplyTo($replyTo->getAddress(), $replyTo->getName());
        $message->getHeaders()->addTextHeader("IsTransactional", "True");

And now all emails sent by ThirtyBees will have the IsTransactional: True header.

Edited by romaric17

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...