18

Is there any code provided by google to forward mail. because i haven't found one. If there is any way to forward mail using GMAIL API with extra content to send with original message. Please help.

Rider
  • 463
  • 1
  • 9
  • 19

3 Answers3

13

I don't see any specific forward operation...

You'll have to:

  1. get the message,
  2. add your extra content to the top of the original message and
  3. change the to address, then
  4. remove any cc and bcc addresses [Per @martin-paucot notes from his actual experience doing this]
  5. send it.

Not much help to you but take note of the Threads.

John Mee
  • 50,179
  • 34
  • 152
  • 186
  • I have extracted multiparts from message and added new multipart in it with new content and now when i send the message it only shows new Content but message contains parts of previous message also can u tell me why ? and what is the solution of this? – Rider Jun 24 '15 at 05:23
  • Well that's a different question: you don't want to add a new multipart part to the message, just prepend some text to the existing message. You would do well to invest some more time researching the format of email messages. – John Mee Jun 24 '15 at 07:16
  • yes, i can prepend the text to existing message but if ihave to add new attachments to the same message then? – Rider Jun 24 '15 at 08:53
  • Then modify the message to include the attachment(s). – John Mee Jun 24 '15 at 10:57
  • @john - I have similar requirement. How did you solve it? Please share the references. – Rashmi Singh Nov 26 '19 at 08:09
  • Any updates? It would be great to use the "forward all" option through the API – dank Jul 23 '22 at 10:49
7

Watch out while doing this procedure !

I used the answer of Jhon Mee to forward all emails from a user to an other one. If you just change the "To:" it will continue to send the emails to everyone in "Cc:" and "Bcc:"

Here is the procedure:

  1. Retreive the email in raw format
  2. Decode the email from base64
  3. Replace the line "To:" with the email you want to forward to
  4. Remove the lines "CC:" and "Bcc:"
  5. Send it
Martin Paucot
  • 1,191
  • 14
  • 30
0

Alternatively, access through IMAP and use a Python library like imaplib.

@Google Devs: Why not give us easy forwarding through your "Gmail API"?

Slawomir
  • 3,194
  • 1
  • 30
  • 36