Page 1 of 1

Rules to send mail alerts

Posted: Fri Nov 10, 2006 10:40 am
by smjhays
Hello,

I need to create a scalix rule that will send a text msg alert when a user receives email.

the message has to be:

"You have received a new email from *****".

I know how to do most of this the only part I can't figure out is the ***** (who to get the From: Address).

Any ideas?

Thx!

Posted: Mon Nov 13, 2006 11:56 am
by smjhays
I have been looking at sxaa but cannot find what I need.

Any ideas?

Posted: Mon Nov 13, 2006 1:02 pm
by btisdall
I don't think you can do this in 'pure sxaa' - I would think along these lines:

    Create a UNIX user on your Scalix box (or another one or your network for that matter) - lets call it 'alerts'.

    Use an sxaa rule to forward mail to the 'alerts' user using the wanted criteria.

    Using procmail, pipe the messages through a script which grabs bits of the forwarded message & uses the info to mail the alert to your SMS gateway.


As far as the script itself goes, you may well not have to re-invent the wheel - try googling around 'sms gateway', 'procmail' 'script' etc.

HTH.

Posted: Mon Nov 13, 2006 1:03 pm
by jcaudell
I would be curious as to how you setup the auto-txt message, if you don't mind.

Posted: Mon Nov 13, 2006 1:21 pm
by btisdall
I'll give the script some thought.

Posted: Tue Nov 14, 2006 1:44 pm
by btisdall
Hi smjhays,

can you tell me what the SMS gateway expects to see in the message from Scalix in order to correctly route the SMS.

Posted: Tue Nov 14, 2006 1:46 pm
by smjhays
I'm not sure. Probably just the basic headers (TO: FROM: REPLY-TO:, etc.).

Posted: Tue Nov 14, 2006 2:11 pm
by btisdall
Can you give an example of the mail you'd need to send in order to generate the SMS.

Posted: Tue Nov 14, 2006 2:49 pm
by smjhays
I was looking at the sxaa.readme and --redirect would work perfectly if we could somehow strip out the body of the message (only send the headers).

As far as the mail setup, I am not sure what you want. I can create a standard message and have it sent to the mobile phone as txt message. We have verizon and they assign us an email address (5551234567@vtext.com) that we can deliver emails to. When you send an email to this address it shows up as a txt msg on the phone. I do not know what they are looking for, but I know that it receives basic emails.

Anyone else can help us out with this one?

Posted: Wed Nov 15, 2006 7:56 am
by btisdall
Well, out of all the possible solutions to your problem this is probably the ugliest & least production-ready - you have been warned :-)

Make sure you have the 'Email::Filter' perl module installed from CPAN or using your package manager.

Save this script as 'smsresend.pl':

Code: Select all

#!/usr/bin/perl
use strict;
use Email::Filter;
my $sms_gw_domain = "vtext.com";
my $mail = Email::Filter->new();
my $mail_from = $mail->from();
my $mail_to = $mail->to();
my $sms_addr = $mail->header("X-Original-To");
$sms_addr =~ s/(\S+\@)\S+/$1$sms_gw_domain/;
my $sendmail = "/usr/sbin/sendmail -t";
my $subject  = "New mail from $mail_from";
my $content  = "You have received a new email from $mail_from";
open(SENDMAIL, "|$sendmail") || die "Cannot open $sendmail: $!";
print SENDMAIL "To: $sms_addr\n";
print SENDMAIL "Reply-to: $mail_from\n";
print SENDMAIL "Subject: $subject\n";
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL "$content\n";
close(SENDMAIL);


Then create a UNIX user 'sms' and use sendmail's alias database to map each number to it, e.g.

Code: Select all

5551234567:      sms
5552234567:      sms
5553234567:      sms
# etc


Use a procmail rule on the sms account like:

Code: Select all

0:w
|/usr/local/bin/smsresend.pl 2>> /tmp/smsresend.out


To tie it all together use a --redirect --retain rule in sxaa e.g 5551234567@yourdomain.com <-- not your SMS gateway!

What the script will do is:

Extract the 'from' address from the redirected message & use this in the subject & body.
Extract the 'X-Original-To' from the redirected message & mangle this so that it becomes the correct gateway address for the user.
Send the mail.

Hope it proves at least interesting!