LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-29-2010, 05:54 PM   #1
ceashton
Member
 
Registered: Nov 2006
Distribution: Slackware 12.2
Posts: 36

Rep: Reputation: 15
Pipe email to extract attachments. Script works, but email sender receives an error!


Dear all,

I'm trying to automatically extract email attachments by piping new email to a perl script. Whilst the script performs as expected, stripping the attachment and delivering them to a directory, the email sender receives an email saying their email wasn't delivered.

The script (755 permissions) I am using to extract the attachments is one I found on the web and may be seen here:

http://tek-tips.com/faqs.cfm?fid=4138

This email account is intended to serve one particular purpose, so I have created a specific email account whereby all messages should be processed. The only filter currectly on this email account is the one that calls the processing script. The filter reads:

Code:
/home/accountname/binChris/unmime.pl
As I mentioned earlier, the script successfully processes the email, delivering MIME attachments to a directory defined in the script, but the email sender receives the following email:

Code:
This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

 pipe to |/home/accountname/binChris/unmime.pl
   generated by MY@RECEIVINGDOMAIN.COM

The following text was generated during the delivery attempt:

------ pipe to |/home/accountname/binChris/unmime.pl
      generated by *MY@RECEIVINGDOMAIN.COM ------

Received: from mail-BLAHBLAH.google.com ([209.85.218.179]:59735)
	by MYWEBSERVER.COM with esmtp (Exim 4.69)
	(envelope-from <MY@EMAILADDRESS.COM>)
	id 1O7cH6-00075b-94
	for MY@RECEIVINGDOMAIN.COM; Thu, 29 Apr 2010 23:32:04 +0100
Received: by bwz27 with SMTP id 27so917348bwz.12
       for <MY@RECEIVINGDOMAIN.COM>; Thu, 29 Apr 2010 15:32:11 -0700 (PDT)
Received: by 10.204.152.17 with SMTP id e17mr6564204bkw.105.1272580330599;
       Thu, 29 Apr 2010 15:32:10 -0700 (PDT)
Received: from MY.LOCAL.COMPUTER (SOMEALPHANUM.bagu.cable.ntl.com [???.???.???.???])
       by mx.google.com with ESMTPS id 14sm482144bwz.2.2010.04.29.15.32.09
       (version=TLSv1/SSLv3 cipher=RC4-MD5);
       Thu, 29 Apr 2010 15:32:09 -0700 (PDT)
Subject: 
From: Chris <MY@EMAILADDRESS.COM>
Content-Type: multipart/alternative; boundary=Apple-Mail-21-67868337
Message-Id: <EDC000E7-65B8-4EF6-A55E-2DE74CFB9B28@times-studios.co.uk>
Date: Thu, 29 Apr 2010 23:32:07 +0100
To: MY@RECEIVINGDOMAIN.COM
Mime-Version: 1.0 (Apple Message framework v1078)
X-Mailer: Apple Mail (2.1078)

Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii
test

... REST OF FILE I"VE CUT
Any pointers would be very much appreciated.

Many thanks,

Chris

PS I am in a shared hosting environment with
Kernel version 2.6.18-128.2.1.el5
cPanel Version 11.25.0-RELEASE
perl v5.8.8
exim (exim-4.69-23.1_cpanel_maildir)
Code:
$ cat /proc/version 
Linux version 2.6.18-128.2.1.el5 (mockbuild@builder16.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)) #1 SMP Tue Jul 14 06:39:56 EDT 2009
 
Old 04-29-2010, 07:02 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by ceashton View Post
Code:
 pipe to |/home/accountname/binChris/unmime.pl
- What does the mail log on the server say about using that alias and pipe command?
- how is the filter called in /etc/aliases?
- should the user exim runs as be allowed to execute scripts in /home/${LOGNAME}/?
 
1 members found this post helpful.
Old 04-30-2010, 10:14 AM   #3
ceashton
Member
 
Registered: Nov 2006
Distribution: Slackware 12.2
Posts: 36

Original Poster
Rep: Reputation: 15
Many thanks for the reply.

Code:
- What does the mail log on the server say about using that alias and pipe command
I'm on a shared hosting account, and so the mail logs aren't readable by myself.

Code:
- how is the filter called in /etc/aliases?
Again, I am on a shared hosting account with cPanel so I have just used the 'user level filtering' > 'add filter' in cPanel, as opposed to editing /etc/aliases directly. There is a text field entitled 'pipe to program', so I assumed there was no need for the pipe. This seemed to be validated by the script actually processing the email even though it returned a 'not delivered' message to the sender. I've tried adding in the pipe and the situation remains the same.

I've also tried creating a .forward file in /home/${LOGNAME}/, but it seems to be being ignored, or else I have an error in it - guess I need the logs!

Code:
- should the user exim runs as be allowed to execute scripts in /home/${LOGNAME}/?
I don't know if the user exim runs as should be allowed to execute scripts in /home/${LOGNAME}/, but it certainly seems as though it can, as it runs the script to produce the extracted attachments. Is that a safe assumption? Whilst I'm debugging this, I have given the script and the directory it writes to 777 permissions just-in-case.

I noticed the perl script I am using (as referenced in my initial post) is from 2003, and I wondered if the age of the script may be the reason for the 'not delivered' message. Hence earlier this morning I started experimenting with uudeview.

In the intervening time however, the hosting provider appears to be having some trouble (none of my sites they host are available), so I am unable to perform any more testing. When the hosting company have resolved their issues I'll let you know haw I get on.

Once again, many thanks for replying,

Chris
 
Old 05-01-2010, 06:04 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by ceashton View Post
I'm on a shared hosting account, and so the mail logs aren't readable by myself.
Bummer.


Quote:
Originally Posted by ceashton View Post
I don't know if the user exim runs as should be allowed to execute scripts in /home/${LOGNAME}/, but it certainly seems as though it can, as it runs the script to produce the extracted attachments. Is that a safe assumption?
Yes, quite.


Quote:
Originally Posted by ceashton View Post
Whilst I'm debugging this, I have given the script and the directory it writes to 777 permissions just-in-case.
Best remove that now then. Just in case.


Quote:
Originally Posted by ceashton View Post
I noticed the perl script I am using (as referenced in my initial post) is from 2003, and I wondered if the age of the script may be the reason for the 'not delivered' message.
If it interacts with the Mail Delivery Agent (MDA) part of Exim in a way the MDA does not get then maybe, yes.
 
Old 01-08-2019, 11:13 AM   #5
jgudmundson
LQ Newbie
 
Registered: Jan 2019
Posts: 1

Rep: Reputation: Disabled
Maybe this will help

I hit the same problem recently while testing a bash script to process the piped email. Offline testing of the script showed it working exactlt as expected with no shell output on any of the 3 paths through the program. Once I made it live, it worked except for the mail delivery error back to the email sender in some cases. I scoured the forums for the solution and clearly people have been having this issue going way way back, so it appeared that it wasn't just some bug in cpanel code. The more obvious problem looked like something with file permissions somewhere. But the script wasn't always failing, so how could it be permissions? Finally it dawned on me: two of the three paths through the program, I exited the shell script with non zero exit codes (eg "exit 1" vs just "exit"). I changed all exits to be just "exit" (ie exit 0) and the problem was solved.

Bottom line: whether you are using perl or php or bash or something else, be very sure that your program exits without signaling the system that a failure occurred, as this will be interpreted as the pipe failing, which results in the email sender getting that very ugly (and probably erroneous) failure message.
 
  


Reply

Tags
attachment, email, extract, perl, pipe


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a script that extract voice mail from email, rename it and then create a file Terry56 Linux - General 6 11-17-2009 03:57 AM
Claws email DNS error 451 Could not identify sender- DNS error 10060 sunny51 Linux - Newbie 2 08-13-2009 08:40 PM
run a shell script/cronjob when any email arrive to specific email address ikillu Linux - General 3 05-30-2009 08:18 AM
script/application to extract attachments from email Murdock1979 Linux - Server 1 05-08-2008 08:36 AM
When account expires user still receives email ganninu Linux - Newbie 3 08-01-2003 05:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration