4

I'm writing a Chrome extension that builds on Gmail and which needs to add several proprietary header fields to the mail header before the message is sent. My app logic goes as follows: after the user composes a message in Gmail and presses Send button, code in the content script intercepts the Click event and I create the header fields. So my question is, how do I access the mail header where I can insert the new fields? I'm looking for something like Message.setHeader() in JavaMail and Android.

FractalBob
  • 3,225
  • 4
  • 29
  • 40

1 Answers1

3

You can't. Gmail doesn't have a provision for the user to add any headers other than Reply-To.

But, if you can show how to manually add a custom header, then we can show you how to automate that with a content script.

Until then, to send an X-header, you'll have to use a different email client. Configure Thunderbird, for example, to use Gmail via IMAP.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • 1
    I already did that. I need to do the same thing for Chrome and Gmail. It can be done with Thunderbird (an associate wrote some Javascript code to do it), so I'm surprised it can't be easily done with Gmail. – FractalBob Jan 04 '13 at 02:15
  • If you had Gmail open in Chrome, and someone told you to compose a message and add a header to it, how would you do it? (That's manually adding.) If there was a way, then we could automate it. But there isn't a way, and Gmail exposes no hooks we can use. ... Thunderbird lets you do a whole lot more than Gmail in Chrome does. – Brock Adams Jan 04 '13 at 02:30
  • I think I figured out a way around this problem. In the button-click handler code, just format a mail message, along with the X- header fields and the To:, From: and Subject: fields (plus the message body and any attachments) gotten from the Gmail Compose window, and use XMLHttpRequest() to send the message, followed by event.stopPropagation() to prevent Gmail from sending it. – FractalBob Jan 04 '13 at 02:36
  • I look forward to seeing your code -- which you should post as an answer. – Brock Adams Jan 04 '13 at 02:40
  • The first thing I need to do is find the spec for WebMail, so I know how to talk to the Gmail SMTP server via HTTP. – FractalBob Jan 04 '13 at 21:20
  • Pretty sure Gmail's HTTP interface is proprietary, and you can't get Greasemonkey to do SMTP. You could [set up a server to relay your XHR posts as emails](https://groups.google.com/forum/?fromgroups=#!topic/greasemonkey-users/4FnHOoor9IA). – Brock Adams Jan 04 '13 at 21:28
  • Yes, I agree. I have some servlet code that does just that, but I need to modify it a bit to connect to the Gmail SMTP server and transmit, via an HTTP request, the user's e-mail address, password, message recipients, proprietary headers, etc. Very straightforward for both sending and reading e-mail. I'm giving you credit for this, Brock, even though we thought of it independently. Thanks. – FractalBob Jan 05 '13 at 04:20
  • You're welcome and good luck. If/once you have a solution working, you should write it up as an answer. – Brock Adams Jan 05 '13 at 05:13
  • I'd guess that after almost a decade, there isn't an answer? (beyond _you can't do that_) – Gwyneth Llewelyn Jul 03 '22 at 00:34