Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: mail2sms for Kannel

by haukex (Monsignor)
on Nov 10, 2017 at 09:54 UTC ( #1203110=note: print w/replies, xml ) Need Help??


in reply to mail2sms for Kannel

Hello Pizu and welcome. You just posted a duplicate of this node here. Please note that the appropriate section for questions is Seekers of Perl Wisdom, which is why I moved your first post (the one I am replying to now) there (Perl Monks Discussion is for discussions about this web site, as the top of the page says) - have a look at PerlMonks for the Absolute Beginner, Where should I post X?, and The Perl Monks Guide to the Monastery. The "permalink" for your post is https://www.perlmonks.org/?node_id=1203105.

Replies are listed 'Best First'.
Re^2: mail2sms for Kannel
by Pizu (Initiate) on Nov 18, 2017 at 13:48 UTC

    Hello all :)

    I managed to do some good progress.. :)

    1 #!/usr/bin/perl -w 2 use strict; 3 use warnings; 4 use Mail::Header; 5 use LWP::UserAgent; 6 use HTTP::Request; 7 use Email::Simple; 8 9 my @liste = (<>); 10 my $header_object = new Mail::Header \@liste, Modify => 0, MailFro +m => "COERCE" ; 11 12 my $to = $header_object->get('To'); 13 my $username = substr($header_object->get('To'), 0, index +($header_object->get('To'), '@')); 14 my $apparently_from = $header_object->get('Return-Path'); 15 my $from = $header_object->get('From'); 16 my $mail_from = $header_object->get('Mail-From'); 17 my $subject = $header_object->get('Subject'); 18 19 20 21 my $email_details = new Email::Simple; 22 23 my $body = $email_details->get('Body'); 24 25 /* Printing to file - testing */ 26 27 my $filename = '/var/scripts/log/mail2sms.txt'; 28 open(my $fh, '>', $filename) or die "Could not open file '$filenam +e' $!"; 29 30 print $fh ' To: ' . $to; 31 print $fh ' From: ' . $from; 32 print $fh ' maybe From: ' . $apparently_from; 33 print $fh ' Subject: ' . $subject; 34 print $fh ' Username: ' . $username; 35 print $fh ' mbox From: ' . (split(/\s+/,$mail_from))[0]; 36 print $fh ' Body: ' . $body; 37 print $fh $/; 38 39 40 41 my $ua = new LWP::UserAgent; 42 $ua->timeout(120); 43 #my $result = `ps -e | grep -v grep|grep smsbox |awk \'{print \$1} +\'`; 44 #my $result = true; 45 46 #if ( $result ne "" ) 47 { 48 my $url="http://x.x.x.x:14013/cgi-bin/sendsms?username=kanneluser& +password=kannelpassword&to=$username&from=mail2sms&text=$subject $bod +y"; 49 my $request = new HTTP::Request('GET', $url); 50 my $response = $ua->request($request); 51 my $content = $response->content(); 52 }

    My Issue is this now, Lines: 21,23 is not working, can someone help me?

    also for the body, is it possible to make it as a single string?

      My Issue is this now, Lines: 21,23 is not working, can someone help me?

      "Not working" - maybe you should have a closer look. Do those lines hold up signs with "ON STRIKE!" written on them?

      You really make it hard to help you. Why did you inject all of those numbers into your source code? Perl is not 1970s home computer BASIC and complains loudly about them:

      X:\>perl 1203732.pl Number found where operator expected at 1203732.pl line 2, near "2" (Missing semicolon on previous line?) Number found where operator expected at 1203732.pl line 9, near "9" (Missing semicolon on previous line?) Number found where operator expected at 1203732.pl line 12, near "12" (Missing semicolon on previous line?) Number found where operator expected at 1203732.pl line 19, near "19" (Missing semicolon on previous line?) Number found where operator expected at 1203732.pl line 20, near "20" (Missing semicolon on previous line?) Number found where operator expected at 1203732.pl line 21, near "21" (Missing semicolon on previous line?) Number found where operator expected at 1203732.pl line 23, near "23" (Missing semicolon on previous line?) Number found where operator expected at 1203732.pl line 25, near "25" (Missing semicolon on previous line?) Bareword found where operator expected at 1203732.pl line 25, near "* +Printing to" (Missing operator before to?) Having no space between pattern and following word is deprecated at 12 +03732.pl line 27. Warning: Use of "log" without parentheses is ambiguous at 1203732.pl l +ine 27. syntax error at 1203732.pl line 2, near "2" "use" not allowed in expression at 1203732.pl line 2, near "2 " "use" not allowed in expression at 1203732.pl line 3, near "3 " "use" not allowed in expression at 1203732.pl line 4, near "4 " "use" not allowed in expression at 1203732.pl line 5, near "5 " "use" not allowed in expression at 1203732.pl line 6, near "6 " "use" not allowed in expression at 1203732.pl line 7, near "7 " Substitution pattern not terminated at 1203732.pl line 35. X:\>

      And for the "not working" lines: What do you expect to happen, what happens instead?

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Hi

        Thanks for your reply.

        Those numbers are line numbers... they are not in the code.

        the script works good without issue apart from line 21 and 23, am going to explain below.

        Also please note that this is my 1st perl script...

        My Issue is that am trying to read the body from the email and i need to add into a single line all the body

        and btw, I am not that stupid.. thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1203110]
help
Chatterbox?
[Discipulus]: thanks choroba.. todo list need a pager..

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2017-11-24 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (348 votes). Check out past polls.

    Notices?