Solved

Sendmail Autoresponder

Posted on 2010-09-08
19
1,779 Views
Last Modified: 2013-12-18
I have perused a few links on how to set up an auto-responder to a message sent to a particular client (info@yourdomain.com).

What i want to happen is if a customer sends a message to a specific e-mail address, the person sending the message will get back, right away, a generic message as an acknowledgment  "We have received your message and will get back with you ASAP"  or something to that effect.

The links i found were confusing.   Can someone point me in the right direction?

Using Sendmail 8.12.11  Redhat Linux Enterprise.
0
Comment
Question by:marchopkins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
19 Comments
 
LVL 27

Accepted Solution

by:
Nopius earned 500 total points
ID: 33633197
Hi.

1) Creatre an autoresponder message in plain text with RFC822 headers, but without To:, like:

/tmp/message.txt:

--[cut]--
From: info <info@mydomain.com>
Subject: this is autoresponder message

Welcome.
--[cut]--

2) Create autoresponder script (it will get original message to stdin, where it should parse From:, create correct response and send it. Here is a sample:

attached /tmp/auto.sh:

3) add a line to /etc/aliases to direct all info@ mail to autoresponder script:

...
info: |/tmp/auto.sh
...

run 'newaliases'

From now it should work.

#!/bin/bash
MESSAGE=/tmp/message.txt
FROM=info@mydomain.com
# our stdin is sender's message with headers
while read line
do
  # we should extract return path only
  case $line in
    ( Return-Path:* )
       # TO is a variable to keep return path
       TO=${line##Return-Path: }
       break
       ;;
  esac
done
# Some checks to avoid mail loops:
# skip empty <>, my own, postmaster and MAIER-DAEMON addresses
case $TO in
  ( *$FROM* | '<>' | *MAILER* | *DAEMON* | *DELIVERY* )
    exit 0
    ;;
esac

# Now compose new message and send it to TO
(echo To: $TO; cat $MESSAGE) | /usr/sbin/sendmail -t -f $FROM

Open in new window

0
 
LVL 27

Expert Comment

by:Nopius
ID: 33633208
/tmp/auto.sh should be executable:

chmod +x /tmp/auto.sh
0
 
LVL 27

Expert Comment

by:Nopius
ID: 33633244
Alternatively, if you are also using Cyrus Imapd on the same host, you may create 'info' user and define a 'Sieve' server-side mail filtering script, that will always send auto-response (this kind of autoresponse can be done with 'vacation' lautoresponder), like:

require "vacation";

vacation
:subject "Hello from autoresponder"
   "Welcome";
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

Author Comment

by:marchopkins
ID: 33636107
I'll give this a try..thanks.
0
 

Author Comment

by:marchopkins
ID: 33636369
Seemed pretty straight forward...I'm getting the following messages

1.  while tailing the logfile:      Sep  9 09:05:04 mail sendmail[20467]: o89D541O020467: from=<user@domain.com>, size=13762, class=0, nrcpts=1, msgid=<49D275F1-AA0A-4D74-AE0F-D81BB9CAF29D@domain.com>, proto=ESMTP, daemon=Daemon1, relay=pix525-domain.com [208.65.69.98]
Sep  9 09:05:04 mail sendmail[20468]: o89D541O020467: to=/temp/auto.sh, ctladdr=<autotest@domain.com> (8/0), delay=00:00:00, xdelay=00:00:00, mailer=*file*, pri=44024, dsn=5.0.0, stat=Can't create output
Sep  9 09:05:04 mail sendmail[20468]: o89D541O020467: o89D541O020468: DSN: Can't create output
 
2.  message back to my mail client:       ----- The following addresses had permanent fatal errors -----
/temp/auto.sh
   (reason: Can't create output)
   (expanded from: <autotest@domain.com>)

  ----- Transcript of session follows -----
550 5.0.0 /temp/auto.sh... Can't create output
Reporting-MTA: dns; mail.domain.com
Received-From-MTA: DNS; pix525-domain.com
Arrival-Date: Thu, 9 Sep 2010 09:05:04 -0400

Final-Recipient: RFC822; autotest@domain.com
X-Actual-Recipient: X-Unix; /temp/auto.sh
Action: failed
Status: 5.3.0
Diagnostic-Code: X-Unix; 73
Last-Attempt-Date: Thu, 9 Sep 2010 09:05:04 -0400

I think i may not understand your step 2 "Creating a Script".   Thanks
0
 
LVL 27

Expert Comment

by:Nopius
ID: 33660330
You forget to add a veritcal line in etc/aliases, should be:

info: |/tmp/auto.sh

Probably your aliases line looks like:

info: /tmp/auto.sh


0
 

Author Comment

by:marchopkins
ID: 33661318
i'll give it a try.  I believe i actually did that at first, but i'll go over it again.


0
 

Author Comment

by:marchopkins
ID: 33661486
after adding the vertical line here is what the logfile generated:

Sep 13 08:31:00 mail sendmail[12457]: o8DCV0fm012457: from=<user@somedomain.com>, size=13752, class=0, nrcpts=1, msgid=<81301B2C-6105-4D36-BF7D-28E6A8431735@domain.com>, proto=ESMTP, daemon=Daemon1, relay=pix525-domain.com [208.X.X.X]
Sep 13 08:31:00 mail smrsh: uid 8: attempt to use "auto.sh" (stat failed)
Sep 13 08:31:00 mail sendmail[12458]: o8DCV0fm012457: to=|/temp/auto.sh, ctladdr=<autotest@domain.com> (8/0), delay=00:00:00, xdelay=00:00:00, mailer=prog, pri=44015, dsn=5.0.0, stat=Service unavailable
Sep 13 08:31:00 mail sendmail[12458]: o8DCV0fm012457: o8DCV0fm012458: DSN: Service unavailable




0
 
LVL 27

Expert Comment

by:Nopius
ID: 33661997
1) Put your script into /etc/smrsh/ and change aliases accordingly.
2) Try to disable selinux temporary (setenforce 0). If 1) doesn't work.

Regards,
Arty
0
 

Author Comment

by:marchopkins
ID: 33662069
I'll give it a go.
0
 

Author Comment

by:marchopkins
ID: 33662280
1 did not work....

I have no /etc/selinux file
I tried to run the command setenforce 0...  Command not found

I also checked the bootloader   /boot/grub   to try to find the grub.conf file....no file there either.


Any other suggestions?
0
 

Author Comment

by:marchopkins
ID: 33662338
BTW, here is the error that i am getting after moving the file:

Sep 13 09:48:46 mail sendmail[14063]: o8DDmkx5014062: to=|/etc/smrsh/auto.sh, ctladdr=<autotest@domain.com> (8/0), delay=00:00:00, xdelay=00:00:00, mailer=prog, pri=33096, dsn=5.3.0, stat=unknown mailer error 127
Sep 13 09:48:46 mail sendmail[14063]: o8DDmkx5014062: o8DDmkx5014063: DSN: unknown mailer error 127


I moved the auto.sh and the care.txt file into the directory you suggested.  Here are the contents of the files.


care.txt:    (it just accured to me that i should probably remove the --[cut}--)

--[cut]--
From: info <autotest@grid4.com>
Subject: this is autoresponder message

Welcome.
--[cut]--


auto.sh:   (I only have the word  "attached"  in this file.)

attached    
 
0
 
LVL 27

Expert Comment

by:Nopius
ID: 33663761
Did you disable SELinux?
Also can you repost a shell script.
0
 

Author Comment

by:marchopkins
ID: 33664358
the commands that you suggested did not work.   See my post prior to the last one.  


Repost a shell script...??
0
 
LVL 27

Expert Comment

by:Nopius
ID: 33668790
I mean you didn't attach your real script and I can't check it.

I guess the problem is here: ctladdr=<autotest@domain.com>

Most probably your server has a fake hostname (either not in DNS or just non existing). And sendmail is unable to resolve it. Please check your /etc/mail/sendmail.cf for a line starting with DS<servername here>, if there is 'localhost' or something like - it's a fake name, you should change it to real domain name, then restart sendmail.

Regards,
Arty
0
 

Author Comment

by:marchopkins
ID: 33671944
Ok, i'll do the best i can to get the info posted here.   Here goes:   (I've never done a script in the past)

Here is the content of the Alias File in /etc/alias:
autotest:       |/etc/smrsh/auto.sh

Here is the content of the /etc/smrsh/auto.sh file:
#!/bin/bash
MESSAGE=/etc/smrsh/care.txt
FROM=autotest@domain.com
# our stdin is sender's message with headers
while read line
do
  # we should extract return path only
  case $line in
    ( Return-Path:* )
       # TO is a variable to keep return path
       TO=${line##Return-Path: }
       break
       ;;
  esac
done
# Some checks to avoid mail loops:
# skip empty <>, my own, postmaster and MAIER-DAEMON addresses
case $TO in
  ( *$FROM* | '<>' | *MAILER* | *DAEMON* | *DELIVERY* )
    exit 0
    ;;
esac

# Now compose new message and send it to TO
(echo To: $TO; cat $MESSAGE) | /usr/sbin/sendmail -t -f $FROM

Here is the content of the care.txt file in /etc/smrsh/care.txt:
From: info <autotest@grid4.com>
Subject: this is autoresponder message

Welcome.

Here is the message that i see when I tail the logfile on the server:

Sep 14 08:54:18 mail sendmail[29457]: AUTH=server, relay=pix525-domain.com [208.x.x.x], authid=<sender>, mech=PLAIN, bits=0
Sep 14 08:54:19 mail sendmail[29457]: o8ECsIrW029457: from=<user@someother.com>, size=13740, class=0, nrcpts=1, msgid=<EC671B83-9E19-464A-8046-61BCD9BE9115@grid4.com>, proto=ESMTP, daemon=Daemon1, relay=pix525-domain.com [208.x.x.x]
Sep 14 08:54:19 mail sendmail[29462]: o8ECsJs3029462: Authentication-Warning: mail.domain.com: mail set sender to autotest@domain.com using -f
Sep 14 08:54:19 mail sendmail[29462]: o8ECsJs3029462: from=autotest@domain.com, size=87, class=0, nrcpts=0, msgid=<201009141254.o8ECsJs3029462@mail.domain.com>, relay=mail@localhost
Sep 14 08:54:19 mail sendmail[29458]: o8ECsIrW029457: to=|/etc/smrsh/auto.sh, ctladdr=<autotest@domain.com> (8/0), delay=00:00:00, xdelay=00:00:00, mailer=prog, pri=44003, dsn=2.0.0, stat=Sent

it appears that the message was sent, but i did not receive a message in my inbox.
0
 
LVL 27

Expert Comment

by:Nopius
ID: 33679284
Hi.

I had checked the autoresponder before initial post. If it doesn't work for you - you are doing something wrong.
Without complete non-modified logs it's hard to guess what is going wrong.

Regards,
Arty
0
 
LVL 27

Expert Comment

by:Nopius
ID: 33679311
You may also try to make a copy of your outgoing mail message with this line:

(echo To: $TO; cat $MESSAGE) | tee /tmp/message.$$ | /usr/sbin/sendmail -t -f $FROM

Then see what is in that file after testing. Then try to send this file manually with 'cat /tmp/message.??? sendmail -t -f autotest@domain.com' (just change ??? to real number).

And provide logs of manual sending too.

Regards,
Arty
0
 

Author Closing Comment

by:marchopkins
ID: 35789007
thanks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Resolve DNS query failed errors for Exchange
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question