Windows Perl Scripting Forums » Perl

email2SMS Kannel &gmail

(1 post)
  • Started 6 years ago by

No tags yet.


  1. Anonymous

    hy, i save setup a Kannel server for sending SMS, and now i vant to send sms via e-mail.
    i found this script but is for pop3 with out SSL.
    o have adapt the script for SSL, but i have a few problems,
    - i can't read all the e-mail at once,
    - i can't go to the next step to sort end complete the URL for Kannel.
    [Code]
    #!/bin/perl

    use Mail::POP3Client;
    use IO::Socket::SSL;
    use CGI qw(:standard);
    $cgi = new CGI;
    use LWP::UserAgent;

    $username = 'email@domanin.ro';
    $password = 'password';

    $mailhost = 'pop.gmail.com'; #examplepop.gmail.com
    $port = '995'; #995

    print $cgi->header();

    $pop = Mail::POP3Client->new(USER => $username,
    PASSWORD => $password,
    HOST => $mailhost,
    PORT => $port,
    USESSL => 'true',
    DEBUG => 0,) or die("ERROR: Unable to connect to mail server.\n");

    if (($pop->Count()) < 1) {
    print "No messages...\n";
    exit;
    }

    my $Messages = $pop->Count();
    my ($MsgDel,$MsgNo);
    my ($MsgId, $MsgDate, $MsgFrom, $MsgTo, $MsgSub, $Delivred_To, $Content);
    my ($MsgAttach, $MsgSize, $MsgHeader, $MsgHeadFlg, $MsgBody, $MIME_Version, $Received_Time, $Origin_IP);

    foreach $MsgNo ( $Messages ) {
    my $MsgContent = $pop->HeadAndBody($MsgNo);
    my $count = 0;
    $MsgHeadFlg = 0;
    $MsgBody = "";

    (my $Mesaj_NR, my $MsgSize) = split('\s+',$pop->List($MsgNo));

    #print $MsgSize . "Marime mesaj \n";
    #print $Mesaj_NR . "Nr. Mesaj \n";
    #print $MsgContent . "\n";

    # Process message data
    while()
    {

    # Exit if last line of mail
    if ($count >= scalar(@$MsgContent))
    {
    #print $MsgContent . "count";
    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 MIME Version
    $LineContent[0] =~ /MIME-Version/i && do
    {
    $MIME_Version = $LineContent[1];
    last SWITCH;
    };
    #Get Time Of recived
    $LineContent[0] =~ /Received/i && do
    {
    $Received_Time = $LineContent[1];
    last SWITCH;
    };
    #Get IP of sender
    $LineContent[0] =~ /X-Originating-IP/i && do
    {
    $Origin_IP = $LineContent[1];
    last SWITCH;
    };
    #Get Date
    $LineContent[0] =~ /Date/i && do
    {
    $MsgDate = $LineContent[1];
    last SWITCH;
    };
    #Get Delivred To
    $LineContent[0] =~ /Delivered-To/i && do
    {
    $Delivred_To = $LineContent[1];
    last SWITCH;
    };
    # Get message id
    $LineContent[0] =~ /Message-ID/i && do
    {
    $MsgId = $LineContent[1];
    last SWITCH;
    };
    # Get message subject
    $LineContent[0] =~ /Subject/i && do
    {
    $MsgSub = $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 Content type
    $LineContent[0] =~ /Content-Type/i && do
    {
    $Content = $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}\';
    my $result = true;

    if ( $result ne "" )
    {
    print $MsgSub . "subiect mesaj \n";
    print $MsgBody . "continut mesaj \n";
    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 = $pop->Delete($MsgNo)
    }
    }

    # Disconnect from pop3 server
    $pop->close();

    exit;

    [/Code]

    please help with this script,
    sorry for my bad english

    Posted 6 years ago #

RSS feed for this topic

Reply

You must log in to post.