SMS Server Tools 3
 Menu
Basic information:
Additional information:
Support:
Get SMS Server Tools 3:
Additional Options

 Sponsored links

 Search
Custom Search

 Visitor locations
 
 SMS Server Tools 3 Community
Welcome, Guest. The forum is currently read-only, but will open soon. Sun Dec 08, 2024 14:27
SMSTools3 Community » Sample scripts / setups Bottom

email2sms-ucs: international version of email2sms

Login and Post Reply

Page:  1  2  Next

Author Post
Member
Registered:
May 2010
Location: Russian Federation
this perl script process MIME headers and work correct with not-latin messages

#!/usr/bin/perl -w

### Maximal SMS body size in bytes, must be even for UCS-2
### remember - SHORT Message Service
my $maxsmssize = 1024;

### Default directories
our $spool_dir = '/var/spool/sms/outgoing/';
our $tmp_dir = '/tmp/';

sub usage {
die <<EOF;
E-mail to SMS converter with non-latin charsets suppport

Usage:
   $0 -n number [-s spool_dir] [-t tmp_dir] [-d] < email-file
       -n number     phone number in international format
       -s spool_dir  outgoing spool directory
                     default: $spool_dir
       -t tmp_dir    temporary directory
                     default: $tmp_dir
       -d            dry-run (do not spool message)

Designed to be used with smstools (http://smstools3.kekekasvi.com)

WARNING! Large e-mail messages can cause DoS.
Limit the size of messages on the mail server.

EOF

}

use MIME::Parser;
use Encode qw/resolve_alias encode decode/;
use Getopt::Std;
use File::Temp qw/ tempfile tempdir /;
use File::Copy;

my  $default_charset = 'ascii';

my %options;
getopts( 'n:ds:t:' , \%options );

unless ( defined  $options{n} ) {
   usage();
}

my $to = $options{n};
my $dry = $options{d};
$spool_dir = ( $options{s} or $spool_dir );
$tmp_dir = ( $options{t} or $tmp_dir );
my $tmpfilename;

my $tfh;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon++;
$year -= 100; # sorry

umask 0113;

($tfh, $tmpfilename) = tempfile(
                               sprintf("SMS-%02d.%02d.%02d-%02d:%02d:%02d-XXXX",
                                       $year, $mon, $mday, $hour, $min, $sec),
                               DIR => $tmp_dir);

open TMP, ">&=", $tfh;

$to =~ s/[ -\.\(\)]//g; # (987)654-32-10 -> 9876543210
$to =~ s/^\+?(\d*)$/$1/ or die "Bad number '$options{n}'?\n";

### Short numbers must be prefixed with 's' char
if ( length($to)<5 ) {
   $to = 's' . $to;
}

print TMP "To: $to\n";

### Create parser, and set some parsing options:
my $parser = new MIME::Parser;

### SMS will be very small
#$parser->output_under("/tmp");
$parser->output_to_core(1);
$parser->tmp_to_core(1);

my $entity = $parser->parse(\*STDIN) or die "parse failed\n";

my $main_ent=$entity;

if (my $num_parts = $entity -> parts()){
   for my $i (1..$num_parts){
       my $e=$entity->parts($i-1);
       if($e->head()->mime_attr('content-type') eq 'text/plain'){
           $main_ent=$e;
           last;
       }
   }
}

my $charset = ( $main_ent->head()->mime_attr('content-type.charset')
               or $default_charset );
$charset = ( resolve_alias($charset) or $default_charset );

my $u8 = decode($charset, $main_ent->bodyhandle->as_string);
my $ascii = encode("ascii", $u8);
my $smsbody;

if ($u8 eq $ascii) {
   $smsbody = $ascii;
} else {
   print TMP "Alphabet: UCS\n";
   $smsbody = encode('ucs-2be',$u8);
}

if (length($smsbody) > $maxsmssize) {
   print STDERR "too large message $tmpfilename, truncated to $maxsmssize bytes\n";
   $smsbody = substr($smsbody, 0, $maxsmssize);
}
print TMP "\n",$smsbody;

close TMP;

if ($dry) {
   print "SMS saved to $tmpfilename\n";
} else {
   move $tmpfilename, $spool_dir or die "moving $tmpfilename to $spool_dir failed\n";
}
 
 
'perl' Syntax Highlight powered by GeSHi


for example you can use it with exim pipe transport:


Member
Registered:
Dec 2011
Location: Germany
Hi,

i use postfix with procmail to execute email2sms (example skript). Now i have to send some mime mails. The orginal script doesn't find any destination. How can i use the shown script with procmail & postfix? I've no idea to integrate it with procmail. Thank you for your help.

Best regards.

Member
Registered:
May 2010
Location: Russian Federation
Topic owner
I suppose that procmail using is not very good idea, because mail can have more than one recipient and only MDA will handle this situation correctly.

I'm unfamiliar with postfix, but according to man it have possibility to run external scripts:
http://www.postfix.org/pipe.8.html

Member
Registered:
Apr 2012
Location: Warsaw, Poland
sms_pipe:
driver = pipe
command = "/usr/local/bin/email2sms-ucs -n $local_part"

How to configure pipe in postfix - master.cf

smstools unix - n n - - pipe ?
flags=DORhu user=smstools argv=/usr/local/bin/email2sms-ucs ?

Thanks
Robert

Member
Registered:
Apr 2012
Location: Warsaw, Poland
Starting with aliases (sms: "| / usr/local/bin/email2sms-ucs.pl") causes errors:



What's the problem?

Thx
Robert

Member
Registered:
May 2010
Location: Russian Federation
Topic owner
what happens if you execute /usr/local/bin/email2sms-ucs.pl from command line?

Member
Registered:
Apr 2012
Location: Warsaw, Poland
I did not use the first line in script #!/usr/bin/perl -w, and I have another problem:



Thx
Robert

Member
Registered:
May 2010
Location: Russian Federation
Topic owner
You must specify recipient number.

I look to http://www.postfix.org/pipe.8.html
It seems like you need add "-n ${user}" argument to email2sms-ucs.pl call

Another thing - email2sms-ucs.pl expect only one recipient per call, so you need specify "transport_destination_recipient_limit = 1" (look to start of man page)

Member
Registered:
Apr 2012
Location: Warsaw, Poland
I added the line in main.cf:
mailbox_transport = smstools
transport_destination_recipient_limit = 1

I set the master cf:
smstools unix - n n - - pipe
flags=DORhu user=smstools argv=/usr/local/bin/email2sms-ucs.pl

Unfortunately it does not work :(, what is the simplest configuration to make it work for postfix?, I'm a novice to set up, please do not send me back to manuals, I'm losing hope it will work ...

Best regards
Robert


« Last edit by Jufo on Mon Apr 23, 2012 17:50, 153 months ago. »
Member
Registered:
May 2010
Location: Russian Federation
Topic owner
I surmise:


but I don't use postfix, so I can't test

Member
Registered:
Apr 2012
Location: Warsaw, Poland
It is better but no logs in smsd.log and do not get sms :/



Thx
Robert


« Last edit by keke on Sun Jun 03, 2012 15:17, 152 months ago. »
Member
Registered:
May 2010
Location: Russian Federation
Topic owner
I use exim with very easy configuration, you can see most of it in first post.

I think you need do some debugging.

Firstly save message from your mail client and try process it with email2sms-ucs.pl:



« Last edit by keke on Sun Jun 03, 2012 15:18, 152 months ago. »
Member
Registered:
Apr 2012
Location: Warsaw, Poland
When you start:



Log /var/log/smsd/smsd.log is clean (only standard massages - Waiting for messages to send...etc), nothing happens :/

Selftest "sms to gsm" is working (su smstools -c "smssend 48XXXXXXXXX 'The Test GSM module.'") - Then, of course, logs are generated.


« Last edit by Jufo on Mon Apr 23, 2012 21:34, 153 months ago. »
Member
Registered:
Apr 2012
Location: Warsaw, Poland
I ran everything on another virtual machine, tomorrow I'll analyze what I broken, I suspect Perl liblary and dns server.

Thank you very much
Robert

Member
Registered:
Apr 2012
Location: Warsaw, Poland
I's works!

In the evening I'll try to share configuration in this Topic ;)

How do I modify the script to create two rules, the selection by the sender (DeliveredTo) ?:

1. The rule in your script

2. Number phone is the subject, the message content is the content of email sms

Thx
Robert

Member
Registered:
May 2010
Location: Russian Federation
Topic owner
sorry, I'm too busy now, may be on next week...
but you can use procmail for this task.

Member
Registered:
Apr 2012
Location: Warsaw, Poland
1. Configuration in postfix:
- In main.cf add line:
mailbox_transport = smstools
transport_destination_recipient_limit = 1

-In master.cf add line:
smstools unix - n n - - pipe
flags= user=smstools argv=/usr/local/bin/email2sms-ucs.pl -n ${user}

2. smstools is default user for smstools, please change permmision for script (to chmod +x /usr/local/bin/email2sms-ucs.pl)

3. Restart postfix service and enjoy ;)

3. To edo, I'll wait for you, in this second rule just changed from To (recipient) on the Subject (only telephone numer). It remains to choose the rules by the sender.

Thx
Robert

Member
Registered:
Jun 2012
Location: Netherlands
I am trying to get it working to.. but i'am unsuccessful so far.
I have smstools3 working and postfix to.

When i run
/usr/local/bin/email2sms-ucs.pl -n +316..... < /var/mail/root

it works!

But when i send a email to root@domein.nl its not working.

My master.cf

smstools unix - n n - - pipe
flags= user=root argv=/usr/local/bin/email2sms-ucs.pl -n ${user}

How can i debug?

Member
Registered:
Jun 2012
Location: Netherlands
Now i get this in my postfix log



Member
Registered:
May 2010
Location: Russian Federation
Topic owner
snowrabbit wrote
But when i send a email to root@domein.nl its not working.
why recipient address is not 316...@domein.nl?

Member
Registered:
Apr 2012
Location: Warsaw, Poland
snowrabbit wrote
How can i debug?

Ok, check configuration main.cf, my configuration:

myhostname = "yourservername.domain"
mydomain = "domain"
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, monitoring.local
local_recipient_maps =
mynetworks = "192.168.1.0/24", 127.0.0.0/8
mailbox_transport = smstools
transport_maps = hash:/etc/postfix/transport (transportmaps for other domain for smtp)
transport_destination_recipient_limit = 1

Robert

Member
Registered:
Jun 2012
Location: Netherlands
Got it working! Thx for the debug tips! :mrgreen:

Member
Registered:
Aug 2012
Location: Austria
Dear All,

I always get following error message:

Aug 6 10:48:57 pandora postfix/smtpd[21239]: connect from ws122.local[10.12.16.122]
Aug 6 10:48:57 pandora postfix/smtpd[21239]: C48051356B8: client=ws122.local[10.12.16.122]
Aug 6 10:48:57 pandora postfix/cleanup[21242]: C48051356B8: message-id=<>
Aug 6 10:48:57 pandora postfix/qmgr[21210]: C48051356B8: from=<sms@pandora.local>, size=673, nrcpt=1 (queue active)
Aug 6 10:48:57 pandora postfix/smtpd[21239]: disconnect from ws122.local[10.12.16.122]
Aug 6 10:48:58 pandora postfix/pipe[21244]: C48051356B8: to=<+43xxxxxxxxxxxx@pandora.local>, orig_to=<sms@pandora.local>, relay=smstools, delay=0.27, delays=0.11/0/0/0.15, dsn=5.3.0, status=bounced (Command died with status 255: "/usr/local/bin/email2sms-ucs.pl". Command output: Can't call method "as_string" on an undefined value at /usr/local/bin/email2sms-ucs.pl line 103, <STDIN> line 20. )
Aug 6 10:48:58 pandora postfix/cleanup[21242]: 107D81356C7: message-id=<20120806084858.107D81356C7@pandora.local>
Aug 6 10:48:58 pandora postfix/qmgr[21210]: 107D81356C7: from=<>, size=2898, nrcpt=1 (queue active)
Aug 6 10:48:58 pandora postfix/bounce[21246]: C48051356B8: sender non-delivery notification: 107D81356C7
Aug 6 10:48:58 pandora postfix/qmgr[21210]: C48051356B8: removed
Aug 6 10:48:58 pandora postfix/pipe[21244]: 107D81356C7: to=<+43xxxxxxxxxxxx@pandora.local>, orig_to=<sms@pandora.local>, relay=smstools, delay=0.11, delays=0.03/0/0/0.08, dsn=2.0.0, status=sent (delivered via smstools service)
Aug 6 10:48:58 pandora postfix/qmgr[21210]: 107D81356C7: removed


The mail is being moved to /var/spool/sms/checked
Content of the SMS file looks very strange.


To: 43xxxxxxxxxxxx
This is the mail system at host pandora.local
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The mail system

<+43xxxxxxxxxxxx@pandora.local> (expanded from <sms@pandora.local>):
Command died with status 255: "/usr/local/bin/email2sms-ucs.pl". Command
output: Can't call method "as_string" on an undefined value at
/usr/local/bin/email2sms-ucs.pl line 103, <STDIN> line 20.


I'm using Postfix like described above.
Am i missing some perl module here?


Kind regards
Jens


« Last edit by jens on Mon Aug 06, 2012 11:15, 150 months ago. »
Member
Registered:
Aug 2012
Location: Austria
Problem solved:

My mail client was sending mails using "html" format.
Changed this to "plain text" now it's working.

Many thx!
Jens

Member
Registered:
May 2010
Location: Russian Federation
Topic owner
jens wrote
<+43xxxxxxxxxxxx@pandora.local> (expanded from <sms@pandora.local>):
Command died with status 255: "/usr/local/bin/email2sms-ucs.pl". Command
output: Can't call method "as_string" on an undefined value at
/usr/local/bin/email2sms-ucs.pl line 103, <STDIN> line 20.

can you send problem mail message to edo.rus@gmail.com? (save it to file and send me this file)

Login and Post Reply

Page:  1  2  Next

SMSTools3 Community » Sample scripts / setups Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.