Add custom variable to email header in gmail inbox

this may seem odd, but I was wondering if it was possible to add personalized header data to emails already in the inbox. For example, let's say I want to add something like myvariable = myvalue to the message header, and then somehow request it. I look through the code from Iloha's mail, and most of the details, such as the subject, as well as received, etc., are in the headers and you can search for them. Can I add my own variable to the email header and request it in the same way? How can this be done with php?

EDIT =====================

Thank you, I know how you can change the headers of sent messages, as well as request custom variables in the message headers, however in this case I want to know whether it is possible to add a user variable to the received message already in my inbox, In fact, let me define situation here.

I'm working on a solution for Google Apps that requires email link support. Basically, the application is such that when an email arrives, we create an order from this email and want to maintain the link to this EXACT email with some identifier that will allow us to identify this email.

The fact is that we do not want to upload emails to the database and maintain a separate store, since we would like to save all the emails on GMAIL. We just need to:

A way to be able to "bind" to a specific email forever - the UID is just a serial number and not very reliable. We could not find any property of the letters that could function as a unique identifier or primary key, so we thought about whether we could generate a key at our end and store it in a user variable in the email itself. However, it seems, unfortunately, there is no way to manipulate the headers of an existing letter.

:( are there any solutions to this problem, I could use any IDEA!

+4
source share
3 answers

Yes, you can add your own headers when sending emails ...

<?php $to = ' nobody@example.com '; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com ' . "\r\n" . 'Reply-To: webmaster@example.com ' . "\r\n" . 'myvariables: myvalue'; mail($to, $subject, $message, $headers); ?> 

I doubt that you can change the existing message headers if they are not stored in the database or something, and not just retrieved from your POP / IMAP server.

+2
source

Why aren't you using the Message-ID header? This should be unique for each email message (you can see it for any Gmail message by clicking on the drop-down menu and selecting "Show Original").

For more information, see section 3.6.4 of the RFC Internet Message Format (RFC2822) ( http://www.faqs.org/rfcs/rfc2822.html ).

+2
source

I think the best solution is either:

  • Connect to the IMAP server, receive emails, change the header, return it to the server, it seems that this is possible with gmail (Example in Java http://forums.sun.com/thread.jspa?threadID=5419712 for PHP see http : //www.php.net/manual/en/ref.imap.php , but changing the header doesn't seem trivial)
  • If you can no longer use gmail or with PHP, connect to the IMAP server, receive emails, copy the content, create a new message with a new header, send it to a new mailbox connected to gmail.

Hope this helps.

+1
source

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


All Articles