Hello. Is it possible and how to implement this:

On my site, a user can send a message to another user, but this message should not come from within the site, but by email. - This is already there.

When a message arrives in the mail, the sender's email should not be visible, instead of it, anything, random characters for example. And after that, if the recipient of the letter replies to this email, already inside the mail itself (Yandex for example), in this case it becomes possible to see both emails of the interlocutors, and they continue to continue to correspond.

Is it possible, and how?

PS - https://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B8%D0%B0%D1%81%D1%8B_%D0%BF%D0%BE%D1%87 % D1% 82% D0% BE% D0% B2% D1% 8B% D1% 85_% D0% B0% D0% B4% D1% 80% D0% B5% D1% 81% D0% BE% D0% B2

For what:

Aliases: you issue an arbitrary set of characters for the From field of the email. The user sends the message, and instead of real soap comes alias. If the user considers it necessary - he will answer, and the site will check for phishing if the alias belongs to this sender. That is, the communications are protected and the spammer does not recognize the real soap if the user does not respond

  • When sending a letter to your first user from your server, indicate in the return address your email on which the robot will sit. Let the robot forward this letter (response) to the second user. In order for the robot to know who to send, specify in the address of the robot a unique generated identifier of the letter. If your email is a robot like myrobot@gmail.com , then you can do so myrobot+jhgjhuUUhfnjfj75858ndjdbash53544@gmail.com . PS Spammers in this way from one address can register and spam a bunch of accounts :) - Visman
  • @Visman and how to implement this robot? - iKey
  • You have the option to answer offered. - Visman

1 answer 1

In fact, you need to deploy a mail service (for example, Postfix), and process the mail included in it via a php script. This article describes such a scheme.

  1. First, make sure you have a working mail server.

You can make a separate mailer in the subdomain, just make 2 entries in the DNS:

 rob.mydomain.ru. A ip-вашего-сервера rob.mydomain.ru. MX rob.mydomain.ru. 
  1. Edit the file with aliases /etc/aliases : add a line there: robot: "|php -q /путь/к/скрипту.php" robot is the name of the mailbox; /путь/к/скрипту.php - script processing incoming.

after editing, run the newaliases command

  1. In the postfix main.cf settings, I recommend adding a parameter: recipient_delimiter = +

then it will be possible to encode additional information in the address: robot+someId@rob.mydomain.ru

All letters to such addresses will also process our script. someId can be a user id or any other data.

  1. create a script-processor of letters:
  <?php /** * Скрипт для автоматической обработки входящих писем * * Все данные smtp-конверта письма RECIPIENT, SENDER и другие postfix * передает через окружение $_ENV; полный перечень переменных: * http://www.postfix.org/local.8.html секция EXTERNAL COMMAND DELIVERY */ //текст сообщения считываем из STDIN $msg = file_get_contents("php://stdin"); //отправитель письма $sender = getenv('SENDER'); //получатель письма $recipient = getenv('RECIPIENT'); //парсинг сообщения list($header, $body) = explode("\n\n", $msg, 2); //выделим строки с Subject: и From: $subject = ''; $from = ''; $headerArr = explode("\n", $header); foreach ($headerArr as $str) { if (strpos($str, 'Subject:') === 0) { $subject = $str; } if (strpos($str, 'From:') === 0) { $from = $str; } } //для отладки сохраняем полученное сообщение в лог: $logMsg = "=== MSG ===\n"; $logMsg .= "SENDER: $sender\n"; $logMsg .= "RECIPIENT: $recipient\n"; $logMsg .= "$from\n"; $logMsg .= "$subject\n\n"; $logMsg .= "$msg\n"; file_put_contents('/tmp/inb.log',$logMsg, FILE_APPEND); 

From A. Gorlova's sathya: https://habrahabr.ru/en/post/126448/

  • Well, would copy the article here with reference to the original. - Visman
  • According to the stackoverflow rules, copying other people's articles is not welcome - Crantisz
  • @Crantisz is so written there: the publication of other people's works without indication of the author is not approved .... it means with an indication you can)) In any case, the link may become outdated and die, and the answer will become useless .... and the author, the answer will have at least some significance - Alexey Shimansky
  • @ AlekseyShimansky well ok - Crantisz