SMS2EMAIL and EMAIL2SMS

Amity, Ronen ronena at ti.com
Thu Jul 31 18:26:33 CEST 2008


I wrote an email2sms perl script.
Read a php3 mailbox.
Phone number to sms is in the subject.
Body is send as the msg.

Regards.

Ronen



Via cronjob I run this every 1 min.
(change the yellow marked )
#!/usr/local/bin/perl -w
use Net::POP3;
use strict;
use LWP::UserAgent;


# Connect to pop3 server
my $pop3 = Net::POP3->new("mailserver.domain.com") || die "Error : Couldn't log+on to server";

# Login to pop3 server
my $Num_Message = $pop3->login("pop3_user", "pop3_passwd");

my $Messages = $pop3->list();
my ($MsgDel,$MsgNo);
my ($MsgId, $MsgDate, $MsgFrom, $MsgTo, $MsgCc, $MsgSub);
my ($MsgAttach, $MsgSize, $MsgHeader, $MsgHeadFlg, $MsgBody);

foreach $MsgNo (keys %$Messages)
{
  my $MsgContent = $pop3->get($MsgNo);
  my $count = 0;
  $MsgHeadFlg = 0;
  $MsgBody = "";

  $MsgSize = $pop3->list($MsgNo);

  # Process message data
  while()
  {

    # Exit if last line of mail
    if ($count >= scalar(@$MsgContent))
    {
      last;
    }

    # Check if end of mail header
    if (@$MsgContent[$count] =~ /^\n/)
    {
      $MsgHeadFlg = 1;
    }

    # Proceed if message header not processed
    if (not $MsgHeadFlg)
    {

      # Split the line
      my @LineContent = split /: /, @$MsgContent[$count];

      # Check Header Info
      SWITCH:
      {
        # Get message date
        $LineContent[0] =~ /Date/i && do
                                       {
                                         $MsgDate = $LineContent[1];
                                         last SWITCH;
                                       };

        # Get message id
        $LineContent[0] =~ /Message-ID/i && do
                                       {
                                         $MsgId = $LineContent[1];
                                         last SWITCH;
                                       };

        # Get message from
        $LineContent[0] =~ /From/i && do
                                      {
                                        $MsgFrom = $LineContent[1];
                                        last SWITCH;
                                      };

        # Get message to
        $LineContent[0] =~ /To/i && do
                                      {
                                        $MsgTo = $LineContent[1];
                                        last SWITCH;
                                      };

        # Get message cc
        $LineContent[0] =~ /Cc/i && do
                                      {
                                        $MsgCc = $LineContent[1];
                                        last SWITCH;
                                      };


        # Get message subject
        $LineContent[0] =~ /Subject/i && do
                                      {
                                        $MsgSub = $LineContent[1];
                                        last SWITCH;
                                      };
      }
    }
    else
    {
      # Process message body
      $MsgBody .= @$MsgContent[$count];
    }
    $count++;
  }
my $ua = new LWP::UserAgent;
$ua->timeout(120);
my $result =  `ps -e | grep  -v grep|grep smsbox |awk \'{print \$1}\'`;

   if ( $result  ne  ""  )
    {
        my $url="http://kennel.domain.com:13013/cgi-bin/sendsms?username=kennel_user&password=kenel_passwd&to=$MsgSub&text=$MsgBody";
        my $request = new HTTP::Request('GET', $url);
        my $response = $ua->request($request);
        my $content = $response->content();
        $MsgDel = $pop3->delete($MsgNo)
    }
}

# Disconnect from pop3 server
$pop3->quit();

From: Djiby SY [mailto:djiby.sy at gsie.sn]
Sent: Wednesday, July 30, 2008 3:09 PM
To: Chen Alkabets
Cc: users at kannel.org
Subject: Re: SMS2EMAIL and EMAIL2SMS

Hi Chen,

It depends on your application that will treat messages (in witch language will you write it ? C, php, java, ...)

Regards,
Djiby


Chen Alkabets a écrit :
Hi Djiby

Thanks for your response. Do u know about any utility/documentation/link about how to do it ? I afraid that this is the only possibility, but I guess im not the first one that trying to do it …

Regards,
Chen Alkabets.
CCIP/CCNP/CCSP/JNCIS.

Mobile  :+224 65 777 772
Office   :+224 65 100 772
MSN    : chenchuk at gmail.com<mailto:chenchuk at gmail.com>
Mail     : chen at gn.cellcomgsm.com<mailto:chen at gn.cellcomgsm.com>, chenchuk at gmail.com<mailto:chenchuk at gmail.com>

From: Djiby SY [mailto:sydjiby at gmail.com] On Behalf Of Djiby SY
Sent: Wednesday, July 30, 2008 11:33 AM
To: Chen Alkabets
Cc: users at kannel.org<mailto:users at kannel.org>
Subject: Re: SMS2EMAIL and EMAIL2SMS

Hi,

There is no POP/SMTP interface in Kannel but you can use kannel to receive sms and then launch your application that send email.
Same in opposite direction.

Regards,

Djiby

Chen Alkabets a écrit :
Hi Guys

is it possible to use Kannel as Email2SMS or SMS2Email  gateway ?
is it possible to have any kind of POP/SMTP interface to get SMS ( instead of HTTP ) via email ? ( and in the opposite direction : to get SMS and send it via POP/SMTP using the same interface ) ?

Thanks .

Regards,
Chen Alkabets.
CCIP/CCNP/CCSP/JNCIS.

Mobile  :+224 65 777 772
Office   :+224 65 100 772
MSN    : chenchuk at gmail.com<mailto:chenchuk at gmail.com>
Mail     : chen at gn.cellcomgsm.com<mailto:chen at gn.cellcomgsm.com>, chenchuk at gmail.com<mailto:chenchuk at gmail.com>




__________ Information from ESET NOD32 Antivirus, version of virus signature database 2942 (20080312) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

________________________________
IMPORTANT: The contents of this email and any attachments are confidential. They are intended for the named recipient(s) only.
If you have received this email in error, please notify the system manager or the sender immediately and do not disclose the contents to anyone or make copies thereof.
*** eSafe scanned this email for viruses, vandals, and malicious content. ***
________________________________


__________ Information from ESET NOD32 Antivirus, version of virus signature database 2942 (20080312) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
________________________________
IMPORTANT: The contents of this email and any attachments are confidential. They are intended for the named recipient(s) only.
If you have received this email in error, please notify the system manager or the sender immediately and do not disclose the contents to anyone or make copies thereof.
*** eSafe scanned this email for viruses, vandals, and malicious content. ***
________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.kannel.org/pipermail/users/attachments/20080731/46fe5b24/attachment-0001.html 


More information about the users mailing list