Additional Header Like x-virtual-mta: template-test only for Testing Templates

pradeep sharma

Active Member
Dear @twisted1919

I want to set a additional custom header on all email relaying for
1. testing templates
2. Campaign Reports
i know i can set a x-header on Servers but i want to set some additional header like
x-virtual-mta: template-test or smthing like that to all emails relaying for above said purpose additional to what we have set on servers.

Why this is important and has to be a important feature for mailwizz ?
when we have a sever like PowerMTA or as delivery server then all campaigns emails goes to PowerMTA Queue. where we have many Virtual MTAs relaying emails & most of the cases just to warmup IPs/to protect reputation we need a constant relaying/controlled relaying as per ISP nature.
This way we all emails going out of mailwizz both for campaign & Testing templates & Reports goes to Queue. and delayed till queue is not cleared.

just to overcome this problem we can set a additional header like X-vrtual-mta: high-priority or testing-template
so all emails relaying for Testing templates/reports will contains additional header apart from what we have set at server level.
What this header will do?
x-virtual-mta header in PowerMTA is used to select specific Virtual MTA/IP to deliver Email emails. if a email contains a x-virtual-mta : high-priority then this email within PowerMTA will be relayed from a virtual MTA name high-priority

<virtual-mta high-priority>
<domain *>
queue-priority 100 //highest Priority
</domain>
smtp-source-host 1.2.3.4 mta.domain.com
</virtual-mta>

the above code in PowerMTA Config file will relay emails from virtaul mta name "high-priority" from IP address 1.2.3.4 and smtp host mta.domain.com with highest priority for all domains and all queue and testing templates emails will not stuck in long queue.

How better it would be if we can set custom header on costumer/customer group as well so that we can decide and prioritize them over rest using above said method.

Please help

Regards

Pradeep
 

frm.mwz

Well-Known Member
Prioritization by various means (header, tag, etc) is a good feature suggestion for outside (pmta, rabbitmq, etc) and internal (w/i mwz) delivery servers, so I second this!
:)
 

twisted1919

Administrator
Staff member
How better it would be if we can set custom header on costumer/customer group as well so that we can decide and prioritize them over rest using above said method.
Would a text box where you'd enter a header per line would suffice? Like:
Code:
X-Whatever1: Some header value
X-Whatever2: Some other value
X-Whatever3: Some other value
If that does it i can have it ready for next version.
Let me know.
 

pradeep sharma

Active Member
Yes @twisted1919 this is what we require..for customer & Customer Group Both (we also need to consider this priority as well if there is a x-header in customer group then and if we set another header in customer then which will be used, customer one, customer group one, or both, it a little tricky)
This feature is also important for all email relaying for testing Templates(Important) & Reports...Please implement it if you can in next version as it will also solve a problem where testing goes in spam as it was sent using regular server which was used to sent campaigns and if we implement this testing email will not go in SPAM as we can use different IP address selected via x-header which is a reserved high Priority virtual mta in PowerMTA..
Regards
Pradeep
 

pradeep sharma

Active Member
Oh Great..
Can you please confirm where you added this facility
for customer?
for customer group?
for Testing template emails?
for Report emails?
Regrads
Pradeep
 

twisted1919

Administrator
Staff member
Nope, it's a global setting that you add for all delivery servers at first. Then you can override it per customer group.
Of course you can further customize it per delivery server instance. So i guess it's flexible enough.
 

pradeep sharma

Active Member
the above said solution will only further help to control email deliver ability on customer group level within delivery servers lets say (vertical)
But we need a x header facility to only put on Template testing Emails & reports Emails (horizontal) with in customer group

the Idea is to route Regular Email Campaigns of all Customer/Customer Groups from some x-Group of IP..... Reports from Some other Group of IPs and Template Testing Emails from Other Group of IPs ...these IPs will be selected by based on x-headers...

So Regular Email Campaigns will have x-header-what-ever : Regular
Testing Templates Emails campaigns will have x-header-what-ever : testing-templates
Reports will have.............................................. .x-header-what-ever : reports
Auto responders will have................................ x-header-what-ever : autoresponders

your solution as discussed till now will give control on vertical level but we need horizontal level as well as we want to route different group of emails differently

i hope i make sense..

Regards
 

twisted1919

Administrator
Staff member
@pradeep sharma - that is very specific so what you can do in that case is to create an extension for your own use case that will do this.
You can hook into "delivery_server_before_send_email" filter hook and add headers depending on situation, as follows:
PHP:
Yii::app()->hooks->addFilter('delivery_server_before_send_email', function($params, $server){
    if ($something) {
        $params['headers'][] = array('name' => 'x', 'value' => 'y');
    }

    if ($somethingElse) {
        $params['headers'][] = array('name' => 'z', 'value' => 'k');
    }
    
    return $params;
});
You can look inside $params to view a lot of data. $server is the server instance.
So i say that the above should be enough to customize this as you wish.
As an example, here's how you check to see if a test email for campaign is being sent:
PHP:
$isTestEmail = false;
if (!MW_IS_CLI) {
  $controller = Yii::app()->getController();
  $action      = $controller->getAction();
  if ( Yii::app()->apps->isAppName('customer') && $controller->id == 'campaigns' && $action->id == 'test' ) {
      $isTestEmail = true;
  }
}
if ($isTestEmail) {
   $params['headers'][] = array('name' => 'z', 'value' => 'k');
}
 

twisted1919

Administrator
Staff member
To find if it's a transactional email or a campaign email:
PHP:
$isTransactional = $isCampaign = false;
if (MW_IS_CLI && Yii::app()->apps->isAppName('console')) {
    $isTransactional = Yii::app()->command->name == 'send-transactional-email';
    $isCampaign = Yii::app()->command->name == 'send-campaigns';
}
To find if it's a list email (like welcome email/confirmation email):
PHP:
$isListEmail = false;
if (!MW_IS_CLI) {
 $controller = Yii::app()->getController();
 if ( Yii::app()->apps->isAppName('frontend') && $controller->id == 'lists' ) {
 $isListEmail = true;
 }
}
 

pradeep sharma

Active Member
My Team is now working on Developing Mailwizz extensions and they Successfully Done few things as of now by developing/writing there own controllers on mailwizz files now we are trying to achieve it by not modifying original file rather then forking original file and writing our code in new files and we need your support as we are new to Yii and also Mailwizz framwork

What we have Done
1. PowerMTA bounce Processor via accounting file (Working-Excellent): PMTA posts bounce DATA in JSON to a webhook inside Mailwizz instantly as soon as a bounce is detected as also with Bounce Type, also works perfect if you have many mailwizz install pushing emails to PowerMTA..powerMTA will post bounce DATA to respective MAilwizz Install.
We have Full control over Type of Bounce(Soft/Hard) you can choose..which you want to mark soft or which you want to mark hard..Bounce Reason now have PowerMTA bounce-catagory details as well.

2. Full Integration of WHMCS with Mailwizz
Now Customer with Signup/Paid/Upgrade/DownGrade at WHMCS and will be Synced with MAilwizz..Login is only done via WHMCS so ..no dual Login for WHMCS/MAilwizz.

3. Custom SPF record like spf.your domain.com for all of your sending IPs as we have with Mandrill or Postmark or Google.

Now we are planning to convert this work in Extension so that it can be reused..for others as well.
 

pradeep sharma

Active Member
Hi Twisted,

Great tutorial on "delivery_server_before_send_email" filter hook and add headers depending on situation. I tried it with creating a new extension , it works smoothly but i got stuck with :
1. send-transactional-email
2. send-campaigns

test template campaigns & lists are working fine . i debugged my extension as well it now has
public $allowedApps = array('*');

I guess "delivery_server_before_send_email" filter hook isn't working for above listed (send-transactional-email & send-campaigns) , is there some other hook for this , or am i missing something ?

i wanted to send different headers for the mail which goes to customer after sending campaigns , that consists of reports on how the campaigns went. i guess that would be with command name "send-campaigns" , although "send-transactional-email" didn't work too.

here is my extension code which is under public function run :

Code:
Yii::app()->hooks->addFilter('delivery_server_before_send_email', function($params, $server){
   
     
            if(!MW_IS_CLI){
                //get current controller
                $controller = Yii::app()->getController();
                //get current action
                $action = $controller->getAction();
            }else{
                $controller = $action = false;
            }
     
     
                   
             //check if controller is campaigns & action is test
             $isTestEmail = false;
       
             if (!MW_IS_CLI && Yii::app()->apps->isAppName('customer') && $controller->id == 'campaigns' && $action->id == 'test' ) {
                 $isTestEmail = true;  
             }
       
       
             //check if controller is lists  (like welcome email/confirmation email)
             $isListEmail = false;
       
            if (!MW_IS_CLI && Yii::app()->apps->isAppName('frontend') && $controller->id == 'lists' ) {
                $isListEmail = true;
            }
       
       
            //check if transactional email or a campaign email
            $isTransactional = $isCampaign = false;
       
            if (MW_IS_CLI && Yii::app()->apps->isAppName('console')) {
                $isTransactional = Yii::app()->command->name == 'send-transactional-email';
                $isCampaign = Yii::app()->command->name == 'send-campaigns';
            }
         
       
             //proceed with adding headers
             if ($isTestEmail) {
                  // This is working
             }
             if ($isListEmail) {
                   // This is working
              }
             if ($isTransactional) {
                  // Not working
             }
             if ($isCampaign) {
                 //Not working
             }
       
            return $params;
    
        });
 
Last edited:

pradeep sharma

Active Member
Hi twisted,
Yep it worked smoothly , thanks for the tip. although i see that all campaigns mail + the stats mail are being sent my same console command : "send-campaigns".
but i figured out a way to send just that stats mail from other smtp server.
Thanks

Regards
Pradeep
 
Top