开发者

Add a custom variable to an email header already within a gmail inbox

this may seem odd but I was wondering if it was possible to add custom header details to emails already in an inbox. Like lets say I wish to add in the Header of the email something like - myvariable = myvalue and then be able to query it somehow. I'm looking at code from Iloha mail and most of the details like subject and from recieved etc are in the headers and you can search through them. SO is it possible to add my own custom variable to an email header and query it in the same way? How can it be done using php?

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

Thanks I know how you can modify the headers of sent messages plus also query for custom variables in message headers however in this case I want to know if it would be possible to add a custom variable in a recieved message already in my inbox. Actually let me define the situation here.

I'm working on a google apps solution which requires maintaining references to emails. Basically the application is as such that when an email comes in - we create an order from that email and wish to maintain a reference to that EXACT email by some kind of identifier which would enable us to identify that em开发者_如何转开发ail.

The fact is that we don't want to download the emails in a database and maintain a separate store as we would want to keep all the emailing on GMAIL. We just need:

A way to be able to 'link' to a specific email permanently - the UID is just a sequence number and not very reliable. We couldn't find any property of emails that could function as a unique ID or primary key and so we thought if we could instead generate a key on our end and store it in a custom variable on the email itself. However it seems unfortunately that there isn't a way to manipulate headers of an already existing email.

:( is there any solution to this problem I could use any IDEA !


Yes you can add your own headers when sending an email...

<?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 you can modify the existing emails headers unless they are stored in a database or something rather than just being retrieved from your POP/IMAP server.


Why don't you use the Message-ID header? That should be unique for every mail message (you can see it for any given Gmail message by clicking on the foldout menu and selecting "Show original").

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


I think the best solution is to either:

  • Connect to IMAP server, retrieve the emails, change header, put it back on the server, it seems at least that it was possible with gmail (Example in Java http://forums.sun.com/thread.jspa?threadID=5419712 for PHP look at http://www.php.net/manual/en/ref.imap.php but changing a header does not seem trivial)
  • If not possible anymore using gmail or with PHP, connect to the IMAP server, retrieve the emails, copy the content, create a new email with the new header, send it to a new mailbox connected to gmail.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜