KSH - mailx - Redirect the undelivered mail

Hi,

I need to create one KSH which will send mail to set of recipients using "mailx" command like below.

mailx -s "Test mail" "test@yahoo.com, test@gmail.com" <$output.txt

The recipients are in different domains (like yahoo, gmail, etc.).

My requirement is, if any mail is undelivered, then I need to re-direct that notification to admin user (email id).

Please let me know if it is possible to re-direct the undelivered mail notification to another mail id.

Thanks.

---------- Post updated 01-06-11 at 04:41 PM ---------- Previous update was 01-05-11 at 11:25 PM ----------

Found one workaround for this.

mailx -r "admin@domain.com" -s "Email subject" "test@yahoo.com" <Emailbody.txt

This will send the undelivered notification to admin@domain.com email address.

But the note here is, if the recipient email address is valid, then they will receive the email with sender as admin@domain.com.

Please suggest if there are any other workaround available.

Thanks.

Sending is no trick, it is automatically receiving and processing. You have to receive all to process any. Devote a new id as sender, and write a cron script on that id to get the mail one message at a time, sort them, save them, and remail any returns to admin. You might also email a summary of other mail to admin once a day, unless all other email if any is a week old. Or, you could mail all non-admin messages to another id.

Otherwise, you are talking about a lot of sendmail.conf programming to make the mail daemon do it, possibly destabilizing it.

You can get each incoming email processed immediately in some configurations using '|command_you_create' in ~/.forward, but this is not well thought of in security circles.

1 Like