Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Using perl scrip to email

  1. #1
    Join Date
    Apr 2007
    Beans
    13
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Using perl scrip to email

    I am trying to use a peal script to send an email. I am using the program motion which will execute something when motion is picked up. I know motion is working correctly because when I type:

    Code:
    ./email.pl
    into the terminal from the directory that this file is from, I get the same result as I do when motion is running:

    Code:
    Content-type: text/html
    and no email. I am using my same email account in the to and from fields, would that be a problem? Also, it's an external account, I don't have an email server set up.

    I also tried using mutt but had no luck there. This was the closest thing I could find that seemed like it should work.

    Is there something I am missing or will this not work?

    Code:
    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    
    $title='A Test';
    $to='myemail@domain.com';
    $from= 'myemail@domain.com';
    $subject='Test';
    
    open(MAIL, "|/usr/sbin/sendmail -t");
    
    ## Mail Header
    print MAIL "To: $to\n";
    print MAIL "From: $from\n";
    print MAIL "Subject: $subject\n\n";
    ## Mail Body
    print MAIL "This is a test\n";
    
    close(MAIL);

  2. #2
    Join Date
    Jun 2007
    Location
    Greater Boston
    Beans
    1,586
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Using perl scrip to email

    Is there a reason you cannot use Perl's built-in mail modules?

    Here are two of many available links I found in Google, searching for perl mail api.

    http://www.perl.com/pub/a/2004/06/10/email.html
    http://docs.proscriptum.com/pure_perl_mail.html
    cmn

  3. #3
    Join Date
    Apr 2005
    Beans
    849

    Re: Using perl scrip to email

    I tried to use command line posting of emails.
    Using some homemade script.
    But I never got the attachment part working.
    So I ended up installing mutt and ssmtp.

    now I can send emails like

    PHP Code:
    echo "emailtext"mutt -a attached.file -"email subject" person.to@email.com 
    Running 8.10 on a lenovo 3000 n200!
    Fingerprint reader doesn't work.

  4. #4
    Join Date
    Apr 2007
    Beans
    13
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Using perl scrip to email

    I give up. I have spent three straight 8 hour evenings trying to get it all working. I tried mailing with mail, mutt, sendmail, and alpine. I tried writing about three perl scripts. I tried three different php scripts and opened them from the web browser (they said they worked, didn't echo the error) but no email. I tried two different ways to upload to flicker. And, I tried three different ways to send messages to twitter.

    I got one to update twitter but it doesn't send messages to my phone. I don't know what it's deal is, something with twitter, I have two accounts and they both follow each other, but no text, oh well.

    Everything comes up with some type of error one way or another. Thanks for trying to help though.

  5. #5
    Join Date
    Jun 2007
    Location
    Greater Boston
    Beans
    1,586
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Using perl scrip to email

    Have you installed the mail utilities package?

    sudo apt-get update
    sudo aptitude install -y mailutils
    cmn

  6. #6
    Join Date
    Apr 2007
    Beans
    13
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Using perl scrip to email

    Ok, I did that and all it did was remove some linux headers. I have run a few of the email scripts and have gotten nothing but:

    Code:
    Content-type: text/html
    and a blank line.

    Or, I just get a blank line and it cancels after a while.

    I will try ftp now.

  7. #7
    Join Date
    Apr 2005
    Beans
    849

    Re: Using perl scrip to email

    ok,
    you really need to elaborate on how you want your email set up.

    Have you installed a working local mailserver?
    Do you use a normal remoter server?
    or do you use something like gmail?
    Running 8.10 on a lenovo 3000 n200!
    Fingerprint reader doesn't work.

  8. #8
    Join Date
    Apr 2007
    Beans
    13
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Using perl scrip to email

    No, I don't have a local mail server set up, I am trying to send it to my yahoo account. I remember being able to do that with php from my website when I had some stuff up on that thing, but then again, it was an actual hosted site and even though I didn't have an email address, it had an email server on it.

    I now have made a perl script to ftp a file to my remote web site and it almost works correctly, but I am still having an issue. I am saving the shockwave flash files as the same name on the linux box and then uploading them with the name_time so that I can upload them again and again to the remote server without overwriting any of them. All of this works great but my problem is that somewhere along the way my files are corrupted.

    I can play the file on the linux box so I know it works fine, but when I download the one from the remote server, it won't play. I have put a delay in so that the computer may have time to complete the swf file before having to upload it (just guessing here) but still no help. Here is what I got.

    Code:
    #!/usr/bin/perl
    use Net::FTP;
    
    # Create Variables
    my $host="domain.com";
    my $directory="./";
    my $motion="/home/user/motion/";
    my $cam1="/home/user/motion/cam1/camshot.swf";
    my $cam2="/home/user/motion/cam2/camshot.swf";
    my $cam1r="/cam1/";
    my $cam2r="/cam2/";
    my $time= time;
    
    # Connect to the server
    $ftp=Net::FTP->new($host,Timeout=>240) or $newerr=1;
      push @ERRORS, "Can't ftp to $host: $!\n" if $newerr;
      myerr() if $newerr;
    print "Connected\n"; 
    
    # Log in to the server
    $ftp->login("user\@domain.com","password") or $newerr=1;
    print "Getting file list";
      push @ERRORS, "Can't login to $host: $!\n" if $newerr;
      $ftp->quit if $newerr;
      myerr() if $newerr; 
    print "Logged in at $time\n";
    
    
    # Move to the remote cam1 directory
    $ftp->cwd($cam1r) or $newerr=1; 
      push @ERRORS, "Can't cd  $!\n" if $newerr;
       myerr() if $newerr;
      $ftp->quit if $newerr;
    
    # Delay before upload
    my $delaytime= time;
    my $newdelaytime= $delaytime + 5;
    print "$delaytime\n";
    while ($delaytime <= $newdelaytime){
      $delaytime= time;
    }
    $delaytime = time;
    print "$delaytime\n";
    
    # copy a single file to the remote server 
    $ftp->put($cam1, "camshot_$time.swf");
    
    # Show files that are in server in cam1 directory
    @files=$ftp->dir or $newerr=1;
      push @ERRORS, "Can't get file list $!\n" if $newerr;
      myerr() if $newerr;
    print "Got  file list\n";   
    foreach(@files) {
      print "$_\n";
      }
    
    # Move to the remote cam2 directory
    $ftp->cwd($cam2r) or $newerr=1; 
      push @ERRORS, "Can't cd  $!\n" if $newerr;
       myerr() if $newerr;
      $ftp->quit if $newerr;
    
    # Delay before upload
    my $delaytime= time;
    my $newdelaytime= $delaytime + 5;
    print "$delaytime\n";
    while ($delaytime <= $newdelaytime){
      $delaytime= time;
    }
    $delaytime = time;
    print "$delaytime\n";
    
    # copy a single file to the remote server 
    $ftp->put($cam2, "camshot_$time.swf");
    
    # Show files that are in server in cam2 directory
    @files=$ftp->dir or $newerr=1;
      push @ERRORS, "Can't get file list $!\n" if $newerr;
      myerr() if $newerr;
    print "Got  file list\n";   
    foreach(@files) {
      print "$_\n";
      }
    
    # Quit FTP
    $ftp->quit; 
    
    sub myerr {
      print "Error: \n";
      print @ERRORS;
      exit 0;
    }
    The program motion is calling this after the motion is no longer detected on camera 2, there is a small delay there too. Everything in terminal goes great with no errors.
    Last edited by kd5gje; December 24th, 2008 at 05:51 AM. Reason: To add how this script is used

  9. #9
    Join Date
    Apr 2005
    Beans
    849

    Re: Using perl scrip to email

    hmm, looks rather complicated.
    I couldn't really see anything mail related.

    However, I think this is how I set up my ssmtp with my gmail. http://www.delodder.be/howto/gmail-w...-based-system/

    good luck
    Running 8.10 on a lenovo 3000 n200!
    Fingerprint reader doesn't work.

  10. #10
    Join Date
    Apr 2007
    Beans
    13
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Using perl scrip to email

    Ok, thanks. I will take a look. I just logged vert term 1 and noticed I have mail, 45 messages. They are all the failed messages that sendmail couldn't get out to my yahoo account. I guess sendmail is working afterall. Anyway, I will take a look at your link.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •