Save copy of outgoing messages in pickup directory

Hi,

I need the possibility to save a copy of all outgoing messages (at least per campaign basis) in the MW pickup directory. The (autoresponder-) campaigns are live and sent out via SES delivery server. So I need a copy of them (as .eml file like I set up "Pickup Directory" as regular DS for his campaign) in the pickup directory to get some testfiles for developing an external app.

Thank you for your appreciated help.
 
@morpheus93 - knowing that this will affect performance, since it does write an email on disk, you can do this, create /apps/init-custom.php file with this content:
PHP:
<?php

Yii::app()->hooks->addFilter('console_command_send_campaigns_before_send_to_subscriber', function($emailParams, $campaign, $subscriber, $customer, $server){

   // create the .eml message
   $message  = $server->getMailer()->getEmailMessage($emailParams);
   
   // this is the path on disk where we will store it, make sure the dir exists, change accordingly, etc
   $filePath = '/tmp/emails/' . $server->getMailer()->getEmailMessageId() . '.eml';

   // and store it
   @file_put_contents($filePath, $message);
   
   // and return the data back to send campaign command
   return $emailParams;
});
 
@twisted1919

Thank you very much for your appreciated help.

I added the code from above to a file named init-custom.php within my MW /apps folder (where also the init.php is located). As $filePath for saving the emails to .eml files I added the absolute path $filePath = '/var/www/web5/files/mw_out_copy/' . $server->getMailer()->getEmailMessageId() . '.eml'; (beginning with my server's mainpath /). MailWizz is installed in a folder named 'mw' under web5 so the absolute path is /var/www/web5/html/mw. But it doesn't save any email message (.eml file) in the "mw_out_copy" folder.

Maybe I got something wrong or could it be that your solutions doesn't work with the 1.4.3 version of MW I'm currently using?

Would be great if you can help me to get this working.
 
@morpheus93 - Add the code here so i can have a look.
Also, try to add some echo statements in it to see what happens when you send the campaign, to see exactly how your code is getting executed.
 
@twisted1919

Okay thank you.

Here is the code I added:

PHP:
<?php

Yii::app()->hooks->addFilter('console_command_send_campaigns_before_send_to_subscriber', function($emailParams, $campaign, $subscriber, $customer, $server){

   // create the .eml message
   $message  = $server->getMailer()->getEmailMessage($emailParams);
 
   // this is the path on disk where we will store it, make sure the dir exists, change accordingly, etc
   $filePath = '/var/www/web9/files/mw_out_copy/' . $server->getMailer()->getEmailMessageId() . '.eml';

   // and store it
   @file_put_contents($filePath, $message);
 
   // and return the data back to send campaign command
   return $emailParams;
});

As I see from the /backend/index.php/misc/campaigns-delivery-logs when I add the code above in the init-custom.php file MW seems not to send emails at all, so simply stops sending out (I didn't change anything regarding DS).
 
Here's the correct version, my bad, i hooked in the wrong filter :-s
PHP:
<?php

Yii::app()->hooks->addFilter('delivery_server_before_send_email', function($emailParams, $server) {
   
   // create the .eml message
   $message  = $server->getMailer()->getEmailMessage($emailParams);
   
   // this is the path on disk where we will store it
   $filePath = '/var/www/web9/files/mw_out_copy/' . $server->getMailer()->getEmailMessageId() . '.eml';
   
   // and store it
   @file_put_contents($filePath, $message);
   
   // and return the data back to send campaign command
   return $emailParams;
});
 
Here's the correct version, my bad, i hooked in the wrong filter :-s
PHP:
<?php

Yii::app()->hooks->addFilter('delivery_server_before_send_email', function($emailParams, $server) {
   
   // create the .eml message
   $message  = $server->getMailer()->getEmailMessage($emailParams);
   
   // this is the path on disk where we will store it
   $filePath = '/var/www/web9/files/mw_out_copy/' . $server->getMailer()->getEmailMessageId() . '.eml';
   
   // and store it
   @file_put_contents($filePath, $message);
   
   // and return the data back to send campaign command
   return $emailParams;
});
Perhaps make this a feature?
Writing to disk these days with most servers having ssd is a snap ;)
 
@frm.mwz - it is a feature already, is called pickup directory delivery server type.
Of course, generally, the DS pickup dir is a feature...
...but the thread was about "Save copy of outgoing messages in pickup directory", as in copy for backup purposes, not to be sent (and then it is gone, hence no copy)...
...and that is why you had the extra code above...
...and !this! is what i addressed when i wrote "Perhaps make this a feature?"
;)
 
gotcha. well, i don't know, as you can see, implementing for whom needs it is very simple, so i don't think we'll make a feature out of this.
 
gotcha. well, i don't know, as you can see, implementing for whom needs it is very simple, so i don't think we'll make a feature out of this.
...i thought since the code is ready above, just throw in the option to choose a folder and viola, another feature added...thx in any case for the above code! :)
 
Back
Top