cancel
Showing results for 
Search instead for 
Did you mean: 

saving mail body

Sudip Hore
Occasional Visitor

saving mail body

Hi,

I want to automate a process of saving the body of a mail in a file whenever a new mail comes in and then delete the mail from a script.

Can you guys share some ideas?

Tia,

Sudip
4 REPLIES
Justo Exposito
Esteemed Contributor

Re: saving mail body

Hi Sudip,

You can edit the /etc/mail/aliases and put something like this:
some_aliases:"|cat - | mailx -s "hola" justo"
This send all the mails received by user some_aliases to other user by mail.

If you put:
some_aliases:"|cat - | scripttocut"
you can do the operation that you want. you only have to develop your scripttocut.
PD: you must run the newaliases command in order to made the changes efective.
Regards,
Justo.
Help is a Beatiful word
Steven Sim Kok Leong
Honored Contributor

Re: saving mail body

Hi,

Have you tried using elm filters? With the ~/.forward, you can direct your inbound email as STDIN into your script.

"|/usr/local/bin/filter"

The elm filter guide can be found at

http://www.math.fu-berlin.de/~guckes/elm/guides/filter

The filter rules reside in $HOME/.elm/filter-rules eg.

$HOME/.elm/filter-rules:
===========================
# $HOME/.elm/filter-rules
#
# Filter rules for the Elm Filter program. Don't change without some
# serious thought. (remember - order counts)
#
# (for Dave Taylor)
# rule 1
if (from contains "!uucp") then delete
# rule 2
to "postmaster" ? save "/tmp/postmaster-mail.%d"
# rule 3
if (to "culture" and lines > 20) ? save "~/Mail/culture"
# rule 4
subject = "filter test" ? forward "hpldat!test"
# rule 5
if [ subject = "elm" ] savecopy "~/Mail/elm-incoming"
# rule 6
subject = "display-to-console" ? execute "cat - > /dev/console"
===========================

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
Email: steven@beepz.com. Homepage: https://www.beepz.com
Eugen Cocalea
Respected Contributor

Re: saving mail body

Hi,

Get and install procmail. You can get it from:

http://hpux.tn.tudelft.nl/hppd/hpux/Networking/Mail/procmail-3.21/

Then, if you want to save every email body to a different file, add this to your .procmailrc file (in your home directory):

:0 b
*
folder/.

To save all email bodies to a single file (appended), add this to the .procmailrc file:

:0 b
*
file

I tested this and it works.

E.
To Live Is To Learn
Sudip Hore
Occasional Visitor

Re: saving mail body

Hi Eugen,

I have installed procmail and put this .procmailrc

PATH=/bin:/usr/bin:/opt/procmail/bin
HOME=/home/c727588
MAILDIR=$HOME/Mail #you'd better make sure it exists
DEFAULT=$MAILDIR/mbox #completely optional
LOGFILE=$MAILDIR/from #recommended

:0 b
*
/home/c727588/config/.

I have put the .forward file as follows

"|exec /opt/procmail/bin/procmail"

I am getting the following error message

$ /home/c727588/.forward: line 1: "|/opt/procmail/bin/procmail"... Addres
s c727588@nuh011.telecom.com.au is unsafe for mailing to programs
/home/c727588/.forward: line 1: "|exec /opt/procmail/bin/procmail"... Address c727588
is unsafe for mailing to programs
Can you help out?

Thanks,

Sudip