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!