📜 ⬆️ ⬇️

Postfix Answering Machine

Greetings readers of this site.

The topic I'm going to raise is not new here, but maybe it will help someone.

So…
')
Given:
1. Configured postfix + cyrus-imap + sasl2. The mail server serves 3 domains (domain1.ru, domain2.ru, domain3.ru)

Task:
Make an "answering machine" to the sender. That is, if the recipient of the letter is on the sick-list and the letter comes to him, then the letter should appear in his own box, and the sender should be answered that, they say, “Ivanov on the sick-list, refer to Petrov on all questions”.

I’ll say right away that there is information on how to do this on the Internet, but I’ll give you a solution that will make the answering machine for each user of each domain separately.
I tried to do some kind of universal script for these purposes, but during the tests I came to the conclusion that it is better to make a script for each user.

Decision:
1. Create a message file /etc/postfix/script/ivanov@domain1.ru.msg with the contents:
Good day. From 01/01/2016 to 01/15/2016 I will be at the hospital, for all questions please call 3432142345435. Thank you.

2. /etc/postfix/master.cf add the following
autoreply_ivanov_domain1 unix - nn - - pipe flags=F user=nobody argv=/etc/postfix/script/autoreply_ivanov_domain1 ${sender} ${recipient} 


3. /etc/postfix/main.cf add
 virtual_alias_maps = hash:/etc/postfix/virtual_alias_maps transport_maps = hash:/etc/postfix/transport 


4. / etc / postfix / transport
 ivanov.autoreply.domain1.ru autoreply_ivanov_domain1: #        ivanov.autoreply.domain1.ru.             . 


5. / etc / postfix / virtual_alias_maps
 ivanov@domain1.ru ivanov@domain1.ru, ivanov@domain1.ru@autoreply@ivanov.autoreply.domain1.ru #        ivanov@domain1.ru        autoreply@ivanov.autoreply.domain1.ru(        master.cf     transport) 


6. Preparing a script for answering a message:
/ etc / postfix / script / autoreply_ivanov_domain1 with content
 #!/bin/bash 1. sender=`echo $1` 2. recipient=`echo $2` 3. name1=`echo $recipient | cut -d @ -f 1` 4. name2=`echo $recipient | cut -d @ -f 2` 5. name=`echo $name1@$name2` 6. text=`cat /etc/postfix/script/$name.msg` 7. /etc/postfix/script/sendEmail/sendEmail -o tls=no -f "REPLY <autoreply@domain1.ru>" -t $sender -u reply -o message-charset=utf-8 -m $text -s 192.168.1.1 -xu autoreply@domain1.ru -xp "111" # .       . 


1-2. Assign the values ​​of other variables received from postfix to variables. These variables will be here from this line in the master.cf file. Argv = / etc / postfix / script / autoreply_ivanov_domain1 $ {sender} $ {recipient}
3-4. The recipient variable will be equal to “ivanov @ domain1.ru @ autoreply @ ivanov.autoreply.domain1.ru” and from here we need to pull out “ivanov@domain1.ru” which we are doing. First, pull the first field “ivanov” to the first separator and then the second field “domain1.ru”
5. After executing this line, the variable name will be ivanov@domain1.ru.
6. The text variable is assigned the value of the contents of the file ivanov@domain1.ru.msg
7. Actually we send the answer to the sender. I think with this line everything is clear, from whom, to whom, what we are sending, through what smtp, the login and password for the autoreply@domain1.ru mailbox, which, by the way, should, of course, be created.

To make an answering machine for other users / domains - all the same, only you need to correctly name the files.

Thanks to all.

Source: https://habr.com/ru/post/305918/


All Articles