|
mailSMSGateway |
|
Mail to SMS Gateway |
|
Send your Email to SMS Service |
|
|
|
H. Stadler |
|
26.06.2012 |
Version: 1.0
|
SMS is one of the most preferred mode of
communication and therefore it would be nice to send an email notification
directly to an sms receiver. This gateway retrieves the mails and place it
to the sms spool directory for sending. |
Table of contents
Advanced configuration of a separate/standalone “sms
domain”.
FAQ – Frequently Asked Questions
MailSmsGateway is a simple interface between mailing and sms services (like smstools3).
Software details:
|
Operating System: |
Linux |
|
Programming Language: |
Perl |
|
License: |
GNU General Public License (GPL) |
How does it work ?
An email client sends mail messages to an email account. The email account can be located under a linux server (sendmail), Microsoft Exchange or any other email server.
You have now 4 possibilities to retrieve the emails and pass it over to the sms service (at the moment smstools3 is supported).
Supported interfaces:
Under *nix systems:
· mailbox (standard email box under linux “/var/spool/mail/<user>
· maildir (see FAQ: How do I create a maildir directory ?)
system independent:
· pop3/pop3s
· imap4
To install the MailtoSMS Gateway software, you will need a System running Linux. Maybe other *nix systems will work too but not yet tested.
The gateway requires an already installed
and runnable smstools3 (http://smstools3.kekekasvi.com).
To download the package visit https://sourceforge.net/projects/mailsmsgateway/
there you will find all the needed stuff.
Where to install the script ?
You can install it under directory /usr/local/bin/MailSmsGateway.
Copy the the program MailSmsGateway to this directory.
Create directory /etc/MailSmsGateway for config file and copy MailSmsGateway.cfg to /etc/MailSmsGateway/MailSmsGateway.cfg
You can also use the “install.sh” script which installs the necessary components automatically.
install.sh <progdir> <configdir>
Default installation path:
<progdir> = /usr/local/bin/MailSmsGateway
<configdir> = /etc/MailSmsGateway
Commandline parameters:
MailSmsGateway
1.0, Copyright (C) 2012 Herbert Stadler
This
program comes with ABSOLUTELY NO WARRANTY;
for
details type "MailSmsGateway -L".
Usage:
MailSmsGateway [-h] [-L] [-v] [-d] [-l debug|info|warn|error|fatal] [-V] [-c
config]
Mail Gateway to SMS Dispatcher
-h
(--help) Help
-d
(--daemon) Run as daemon
-l
(--loglevel) Define loglevel
-V
(--version) Program version
-v
(--verbose) Print some useful
information
-L
(--license) Print license
information
-c
(--config) Configuration File
(Default:
/etc/MailSmsGateway/MailSmsGateway.cfg)
Copy MailSmsGatewayd to /etc/init.d and install it with
chkconfig –-add MailSmsGatewayd
may be you have to adapt the program path.
There are some versions of scripts depending on the linux distribution (directory initscripts):
Red Hat:
· MailSmsGatewayd_RedHatStyle
SUSE:
· MailSmsGatewayd_SuseStyle
Example:
*/5 * * * * /usr/local/bin/MailSmsGateway/MailSmsGateway
1. Try to start the program after installation interactively:
enter:
/usr/local/bin/MailSmsGateway/MailSmsGateway
If you get some error messages check headline “Additional software needed”.
Try to install all missing perl modules.
2. Configure configuration file
/etc/MailSmsGateway/MailSmsGateway.cfg
Please keep in mind if you use a user with already existing mails the mails will be DELETED. So always use a “test account” or an “empty account” for the first trials.
3. Check logfile
cat /var/log/MailSmsGateway.log
4. Send test mails to this newly created account
under Linux (testaccount smstest):
mail -s "Test sms" "4399999887755<smstest@domain.com>" < /dev/null
and see if you receive the mail.
In this case you have to configure:
“MAILBOX_SMSFIELD” with “displayname” (because we use the displayname and not the username for the sms number).
5. Start program again and check logfile
analyze logfile if you could fetch the mail.
Example:
Aug 7 10:39:02 - DEBUG: Processing MailboxNo: 04
Aug 7 10:39:02 - DEBUG: Processing mailbox imap4
- vielmo01, smstest, INBOX
Aug 7 10:39:02 - DEBUG: Number of messages: 1
Aug 7 10:39:02 - DEBUG: Mail Nr. 1
Aug 7 10:39:02 - DEBUG: FROM:
Aug 7 10:39:02 - DEBUG: address: root@domain.com
Aug 7 10:39:02 - DEBUG: name : Root
Aug 7 10:39:02 - DEBUG: host : domain.com
Aug 7 10:39:02 - DEBUG: user : root
Aug 7 10:39:02 - DEBUG: comment:
Aug 7 10:39:02 - DEBUG: phrase : root
Aug 7 10:39:02 - DEBUG: TO:
Aug 7 10:39:02 - DEBUG: address:
smstest@domain.com
Aug 7 10:39:02 - DEBUG: name :
Aug 7 10:39:02 - DEBUG: host : domain.com
Aug 7 10:39:02 - DEBUG: user : smstest
Aug 7 10:39:02 - DEBUG: comment:
Aug 7 10:39:02 - DEBUG: phrase : 4399999887755
Aug 7 10:39:02 - DEBUG: Mail arrived from:
root@domain.com
Aug 7 10:39:02 - DEBUG: SMS send user : smstest
Aug 7 10:39:02 - DEBUG: SMS send phrase : 4399999887755
Aug 7 10:39:02 - DEBUG: Mail Subject : testsms
Aug 7 10:39:02 - DEBUG: write SMS from: root@domain.com
to: 4399999887755, testsms
Aug 7 10:39:02 - INFO: SMS transfered to SMS spool for sending: 4399999887755 - testsms
Aug 7 10:39:02 - DEBUG: Sleeping 60 sec
If you want a separate domain for sms handling like “@sms.domain.com” how do I configure this ?
In this case you don’t need a user, you can write an email directly with the sms number like:
mail -s "Test sms" 4399999887755@sms.domain.com < /dev/null
The received mails will automatically be forwarded to a defined user (in our example to user sms – see example below).
Before you configure this example check if standard sendmail functionality works as usual (adapt /etc/mail/sendmail.mc).
Example
configuration for sendmail.
adapt
/etc/mail/virtusertable, append:
@sms.domain.com sms
adapt „/etc/mail/local-host-names:
cat
local-host-names
#
local-host-names - include all aliases for your machine here.
sms.domain.com
With this configuration all emails
should be sent do user “sms”. All processing of the emails works like defined
above.
Where to check in case of troubles ?
Have a look in:
/var/log/MailSmsGateway_*
/var/log/MailSmsGateway.log
example:
/var/log/MailSmsGateway_STDERR_cGoRvN.log
for pop3s:
install openssl
install openssl-devel
Which Perl-Modules do I need to install ?
Mail::Box
Date::Calc
IO::Socket::SSL
and maybe a lot of prerequisites too.
Check if module is installed:
linux-q9do:~
# cpan -D Mail::Box
CPAN:
Storable loaded ok (v2.18)
Going
to read /root/.cpan/Metadata
Database was generated on Fri, 22 Jun 2012
08:47:04 GMT
Mail::Box
-------------------------------------------------------------------------
Mail folder manager and MUA backend
M/MA/MARKOV/Mail-Box-2.105.tar.gz
Installed:
CPAN: 2.105
Not up to date
Mark Overmeer (MARKOV)
Install with:
cpan <Modulename>
Some documentation about installing perl modules.
http://perl.about.com/od/packagesmodules/qt/perlcpan.htm
How to install it in interactive mode:
enter “cpan” in shell mode
enter “install <module-name>”
Please check also if the following linux packages are installed:
· gcc
· make
If not install it with
Redhat:
yum install gcc
yum install make
Suse:
zypper install gcc
zypper install make
How to customize the configuration ?
#
#
Configuration file for Mail Gateway to SMS Dispatcher
#
Copyright (C) 2012 by Herbert Stadler
#
email: hestadler@gmx.at
#
#
#
which mailbox/maildir to read, mailbox without "/" at the end,
#
maildir with "/" at the end
#
wikipedia gives some detail explanation about the formats.
#
Different mailbox types are possible, check happens in sequential
#
order.
#MAILBOX_TYPE_01 =mbox
#MAILBOX_FOLDER_01 =/var/spool/mail/<mailboxname>
MAILBOX_TYPE_02 =maildir
MAILBOX_FOLDER_02 =/home/sms/maildir/
#
which field contains the sms number ?
#
typical emailaddress "displayname<username@domain.com>"
#
choose between "username|displayname"
MAILBOX_SMSFIELD_02 =username
#MAILBOX_TYPE_03 =pop3 || pop3s
#MAILBOX_USERNAME_03 =smstest
#MAILBOX_PASSWORD_03 =smstestsmstest123
#MAILBOX_SERVERNAME_03 =<servername>
#MAILBOX_SERVERPORT_03 =110
#MAILBOX_SMSFIELD_03 =displayname
MAILBOX_TYPE_04 =imap4
MAILBOX_USERNAME_04 =smstest
MAILBOX_PASSWORD_04 =smstestsmstest123
MAILBOX_SERVERNAME_04 =<servername>
MAILBOX_SMSFIELD_04 =displayname
#MAILBOX_SERVERPORT_04 =143
MAILBOX_FOLDER_04 =INBOX
#
number of seconds to sleep till next processing step
#
only in DAEMON_MODE
SLEEP_DAEMON_SECS=60
#
Level of logging (debug,info,warn,error,fatal)
LOGLEVEL=debug
#
Semaphorefile for daemon locking, to run only once in a system
SEMAPHOREFILE=/var/lock/MailSmsGateway/MailSmsGateway.sem
#
Logfile for output of messages
LOGFILE=/var/log/MailSmsGateway.log
#
max. size in bytes, if greater file will be deleted and start from size 0
#
if size = 0, the file will grow as big as the filesystem allow
MAX_LOGFILE_SIZE=1000000
#
Write statistic values to file (on=1, off=0)
WRITE_STATISTICS=1
#
Statisticsfile will be created (D=daily,W=weekly,M=monthly,Y=yearly
STATISTICS_PERIOD=W
#
where should we write the statistics files
STATISTICS_PATH=/tmp
#
-------------------- SMS Parameters --------------------
#
SMS Functionality active
#
Interface available for: SMS Server Tools 3 - http://smstools3.kekekasvi.com/
#
for testing purposes you can turn it off
SERVICE_SMS_ACTIVE=1
#
Interface available for: SMS Server Tools 3 - http://smstools3.kekekasvi.com/
#
at the moment only this tool is supported
SMS_INTERFACE=SMSTOOLS3
#
where is the spool directory for SMS
SMS_SPOOLDIR=/var/spool/sms/outgoing
If I use
mailbox/maildir what components should I install/configure/check ?
·
Configuration of mail server (sendmail,postfix,…)
·
Send mails to Internet, Corporate Network
·
Receive mails from Internet, Corporate Network
My “pop”
connection doesn’t work, what can I do ?
telnet <pop
host> <port>
<port>
typically 110
pop3s over ssl
995
My “imap”
connection doesn’t work, what can I do ?
telnet
<imap host> <port>
<port>
typically 143
imaps over ssl
993
How do I
create a maildir directory ?
example for user “sms”:
useradd sms
su – sms
create file “.procmailrc”
vi .procmailrc
Content:
#
activate if needed
#LOGFILE="/tmp/procmail_sms.log"
:0
maildir/
If you send an email to user “sms” you should see a file in directory
“/home/sms/maildir/new”
mailbox “/var/spool/mail/sms” isn’t used anymore !!
How to
rotate the log ?
Create in /etc/logrotate.d a file “MailSmsGateway” with the following content:
/var/log/MailSmsGateway.log {
nocompress
missingok
prerotate
/bin/kill -HUP `cat
/var/run/MailSmsGateway.pid 2> /dev/null` 2> /dev/null || true
endscript
}
What is a
displayname / username ?
I think this example explains it.
mail -s "Test sms" "displayname<username@domain.com>" < /dev/null