Save copy of outgoing messages in pickup directory

Discussion in 'General discussions' started by morpheus93, Feb 11, 2019 at 6:02 PM.

  1. morpheus93

    morpheus93 Member

    Joined:
    May 5, 2017
    Messages:
    49
    Likes Received:
    3
    S.E:
    2019-11-24 22:51:43
    L.T:
    Regular
    L.C:
    2
    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.
     
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    9,852
    Likes Received:
    2,311
    @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;
    });
     
  3. morpheus93

    morpheus93 Member

    Joined:
    May 5, 2017
    Messages:
    49
    Likes Received:
    3
    S.E:
    2019-11-24 22:51:43
    L.T:
    Regular
    L.C:
    2
    @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.
     
  4. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    9,852
    Likes Received:
    2,311
    @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.
     
  5. morpheus93

    morpheus93 Member

    Joined:
    May 5, 2017
    Messages:
    49
    Likes Received:
    3
    S.E:
    2019-11-24 22:51:43
    L.T:
    Regular
    L.C:
    2
    @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).
     
  6. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    9,852
    Likes Received:
    2,311
    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;
    });
     

Share This Page