email postfix/dovecot (php) : send Delivery Status Notification

Discussion in 'Server Operation' started by electronico_nc, Oct 8, 2021 at 7:09 AM.

  1. Hi all,

    We have a PHP script that :
    - looks for new email in mailbox
    - check if sender is on authorize list (to threat email)
    - do several things based on body content
    - mark email as SEEN
    - move to OK or FAILED folders (imap)
    Some senders require a DSN using this header tag in their email :
    Code:
    X-Confirm-Reading-To: <[email protected]>
    So we would like to generate the 'return receipt read' to original sender.
    Despite seeking for solution, I haven't found yet an option to proceed this from a PHP script.

    Server is
    Ubuntu 18.04 LTS
    ISPConfig 3.2.5
    (the receiver mailbox is a catchall one for receiver domain, so custom rules may be applied)
    postfix v3.3.0
    dovecot 2.2.33.2
    php 7.2 (can be adjusted if needed)

    Thanks in advance for your thoughts !

    The basics of the php script :
    Code:
    $sender_email = '[email protected]';
    $mailbox = imap_open($host, $username, $password) or die("Connection failed : " . imap_last_error());
    $mailbox_check = imap_search($mailbox, 'UNSEEN FROM "' . $sender_email . '"', SE_UID);
    if ($mailbox_check) {
       foreach ($mailbox_check as $key => $uid) {
           $info = imap_fetch_overview($mailbox, $uid, FT_UID);
           foreach ($info as $overview) {
               $msgno = $overview->msgno;
               /** do job on email there : done */
               $email_status = imap_setflag_full($mailbox, "$msgno", "\\Seen");
               /** send DSN to sender : how-to ? */
               imap_mail_move($mailbox, $uid, "INBOX.OK", CP_UID);
            }
       }
    }
    
     
  2. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    You would need to generate the email to send and send it via smtp. I don't know exactly what such a reply looks like, but you could generate one with a regular mail client as an example, or search for how to construct one from a message you have received.
     
    electronico_nc likes this.
  3. Hi Jesse,
    I thought a library or such exists to accomplish this, but it doesn't seem.
    I'll forge the DSN.
    Thanks !
     

Share This Page