I want to create an e-mail account that will upload attached files to a specified folder. What is the best way to do this?
I have the following script (from http://tech.jeffri.es/2010/09/automatic-ripping-and-saving-email-attachments-with-postfix/ )
#!/bin/bash
Version 1.0 of script to save mail attachments
Requires ripmime
INSPECT_DIR=/var/spool/mailrip/son4r/
TARGET_DIR=/home/son4r/public_html/dropbox/
SN=“son4rdropbox:”
Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
Clean up when done or when aborting.
trap “rm -f in.$$ textfile” 0 1 2 3 15
echo “$SN Starting scan of incoming email”
Start processing.
cd $INSPECT_DIR || {
echo “$SN $INSPECT_DIR does not exist”; exit $EX_TEMPFAIL; }
cat >in.$$ || {
echo “$SN: Cannot save mail to file”; exit $EX_TEMPFAIL; }
Now invoke ripmime to process the temporary file
echo “$SN Invoking ripmime”
/usr/local/bin/ripmime -v --prefix -i in.$$ || {
echo “$SN Ripmime failed”; exit $EX_TEMPFAIL; }
NUM_SOURCE_FILES=ls -1 *.pdf | wc -l
if [ $NUM_SOURCE_FILES -gt 0 ]; then
for f in .
do
TARGET_FILE=${TARGET_DIR}$$_$f
echo "$SN Setting perms and copying $f to $TARGET_FILE"
chmod 775 $f
mv $f $TARGET_FILE
done
else
echo “$SN No files to copy”
fi
We DON’T re-inject the message back into postfix via sendmail!
exit $?
and have virtualmin set to pipe dropbox@son4r.com to this script (as “apply filter file”) in the mail aliases for that domain.
I keep getting the following no matter what permissions I set on my folders
Sep 20 15:38:25 son4r postfix/qmgr[26247]: D9D83EE09C: from=m.stants@shaw.ca, size=37097, nrcpt=1 (queue active)
Sep 20 15:38:25 son4r postfix/trivial-rewrite[26506]: warning: do not list domain digaserveworld.com in BOTH mydestination and virtual_alias_domains
Sep 20 15:38:25 son4r postfix/local[26508]: D9D83EE09C: to=dropbox-son4r.com@digaserveworld.com, orig_to=dropbox@son4r.com, relay=local, delay=0.34, delays=0.31/0.01/0/0.02, dsn=5.3.0, status=bounced (Command died with status 1: “/etc/webmin/virtual-server/filter.pl /var/spool/mailrip/son4r/dropbox dropbox”. Command output: Filter file /var/spool/mailrip/son4r/dropbox does not exist! )
Sep 20 15:38:25 son4r postfix/cleanup[26507]: 2FA84EE09D: message-id=20110920213825.2FA84EE09D@digaserveworld.com
Sep 20 15:38:25 son4r postfix/bounce[26510]: D9D83EE09C: sender non-delivery notification: 2FA84EE09D
Sep 20 15:38:25 son4r postfix/qmgr[26247]: 2FA84EE09D: from=<>, size=39166, nrcpt=1 (queue active)
Sep 20 15:38:25 son4r postfix/qmgr[26247]: D9D83EE09C: removed
Sep 20 15:38:25 son4r postfix/smtp[26511]: 2FA84EE09D: to=m.stants@shaw.ca, relay=idcmail.shaw.ca[64.59.134.8]:25, delay=0.38, delays=0.01/0.01/0.15/0.21, dsn=2.0.0, status=sent (250 ok: Message 1284302474 accepted)
Sep 20 15:38:25 son4r postfix/qmgr[26247]: 2FA84EE09D: removed
Sep 20 15:38:30 son4r postfix/smtpd[26502]: disconnect from idcmail-mo1so.shaw.ca[24.71.223.10]
Suggestions?
Howdy,
The error you’re getting is that the file “/var/spool/mailrip/son4r/dropbox” doesn’t exist. Does that file actually exist on your system?
-Eric
Of course it does eric.
root@son4r:/var/spool/mailrip/son4r# pwd
/var/spool/mailrip/son4r
root@son4r:/var/spool/mailrip/son4r# ls -lah
total 12K
drwxr-xr-x 2 postfix postfix 4.0K Sep 20 15:28 .
drwx------ 3 postfix postfix 4.0K Sep 20 15:16 ..
-rwxrwxrwx 1 postfix postfix 1.2K Sep 20 15:28 dropbox
I’ve also tried setting the owner/group permissions to root and to the username that owns that virtual server.
If I pipe the mail directly to the file instead of as filter, i get a permission error. “Permission Denied” but it does recognize the file that way.