condition: mail to specific recipient as attachment

Junior Member
User avatar
Posts: 39
Joined: Thu Nov 15, 2007 12:37 pm

condition: mail to specific recipient as attachment

Postby jheyne » Fri Apr 27, 2012 8:53 am

Hallo,
i need a solution for this "Problem":
if a specific recipient is in "to" - field, then send this mail as an attachment (.eml) to this specific user, the original mail should not be sent. Every other recipients should get the original mail.
How can i achieve this?

regards
Joerg

Developer
User avatar
Posts: 4431
Joined: Tue Apr 20, 2004 3:43 pm

Postby Alexander Telegin » Fri Apr 27, 2012 1:38 pm

Impossible if you really mean the 'To' email field as at that stage mail server already has the list of recipients and approved it.

Tricky, but possible with API. You will need to intercept RCPT TO commands at OnCommand event, and if command contains RCPT TO: <some_email> replace that command with NOOP and set some session flag, for example "send_as_attach". Later at OnMessage event check if session flag is set and send email as attachment.

It might look like this:

OnCommand:
Code: Select all
if ( stripos( $EW_SESSION['command'], 'RCPT TO:' ) !== false
   && stripos( $EW_SESSION['command'], 'some_email@email.com' ) !== false ){   
   $EW_SESSION['send_as_attach'] = true;   
   $EW_SESSION['command'] = 'NOOP';
}


OnMessage:
Code: Select all
if ( $EW_SESSION['send_as_attach'] ){
// set some variables
$sender = 'jheyne@domain.com';
$rcpt = 'alex@sssolutions.net';
$subject = 'Email is attached!';
$text = 'The original email is attached';

// store email into temporary file
$filename = "c:\\temp\\$EW_SESSION[sid].eml";                         
$EW_MSG->save_to_file( $filename );

// load email to string
$email = file_get_contents( $filename );

// load attachment template
$template = file_get_contents( 'c:\\attach_template.eml' );

// replace the placeholders
$template = str_replace( '{DATE}', date('r'), $template );
$template = str_replace( '{EMAIL}', $email, $template );
$template = str_replace( '{SENDER}', $sender, $template );
$template = str_replace( '{RCPT}', $rcpt, $template );
$template = str_replace( '{SUBJECT}', $subject, $template );
$template = str_replace( '{TEXT}', quoted_printable_encode ( $text ), $template );

// save modified template
file_put_contents( $filename, $template );

// load into TMessage object
$msg = ew_object('TMessage');
$msg->load_from_file( $filename );
// send email
ew_send_mail( $sender, $rcpt, $msg );

// delete temporary file
unlink( $filename );
}


You will also need the email attachment template. It's attached in zip. You need to unpack it to some folder and adjust path in script above as in my example it's expected at c:\attach_template.eml.

Regards,
Alex
Attachments
attach_template.zip
(460 Bytes) Downloaded 214 times

Junior Member
User avatar
Posts: 39
Joined: Thu Nov 15, 2007 12:37 pm

Postby jheyne » Wed May 02, 2012 7:26 am

Hello Alex,
thank you for the answer.
Is this PHP Code?
Does it work on eWall 3.0?
Regards
Joerg

Developer
User avatar
Posts: 4431
Joined: Tue Apr 20, 2004 3:43 pm

Postby Alexander Telegin » Wed May 02, 2012 3:23 pm

Oh, the code was for eWall 4.0. I'll try write the same for eWall 3.0.

Developer
User avatar
Posts: 4431
Joined: Tue Apr 20, 2004 3:43 pm

Postby Alexander Telegin » Tue May 15, 2012 7:52 pm

Sorry for the delay. I just have figured out that in eWall 3.0 you only need simple filter. Add an account into eWall which will receive the message as attachment and add following filter to this account under OnMessage:

Code: Select all
if anything
then send as attachment at {X-EW-To}
and delete message


If filter won't trigger, add the empty filter into the root of OnMessage:

Code: Select all
if anything
then cancel deletion


(this filter does nothing, it's just a bug workaround, when there's no filters in root eWall might skip the account filter)

Developer
User avatar
Posts: 4431
Joined: Tue Apr 20, 2004 3:43 pm

Postby Alexander Telegin » Tue May 15, 2012 7:52 pm

Sorry for the delay. I just have figured out that in eWall 3.0 you only need simple filter. Add an account into eWall which will receive the message as attachment and add following filter to this account under OnMessage:

Code: Select all
if anything
then send as attachment at {X-EW-To}
and delete message


If filter won't trigger, add the empty filter into the root of OnMessage:

Code: Select all
if anything
then cancel deletion


(this filter does nothing, it's just a bug workaround, when there's no filters in root eWall might skip the account filter)

Junior Member
User avatar
Posts: 39
Joined: Thu Nov 15, 2007 12:37 pm

Postby jheyne » Wed May 16, 2012 7:13 am

Hi Alex,
thank you for the answer.
unfortunatly the "to"-field in the Mail is empty.
How can "fill" the "to"-field when i use the Filter:

Code:
if anything
then send as attachment at {X-EW-To}
and delete message

Regards
Joerg

Developer
User avatar
Posts: 4431
Joined: Tue Apr 20, 2004 3:43 pm

Postby Alexander Telegin » Wed May 16, 2012 4:42 pm

The filter allows you to any header field into new composed email. Please try add field To with value {X-EW-To}.

Junior Member
User avatar
Posts: 39
Joined: Thu Nov 15, 2007 12:37 pm

Postby jheyne » Mon May 21, 2012 7:41 am

I tried that allready, but when i receive the message with Outlook the "to" field is still empty.

unfortunatly this field is very important for our customers.

Thanks
joerg

Junior Member
User avatar
Posts: 39
Joined: Thu Nov 15, 2007 12:37 pm

Postby jheyne » Mon May 21, 2012 7:57 am


Next

Return to Filters and scripts

Who is online

Users browsing this forum: No registered users and 1 guest