Compose e-mail via URL-params (googlemail)
Asked Answered
S

3

1

I'm working on an extension for chrome, where i need to compose gmail messages from URL. Anyone knows how i set the recipient and the subject via URL-Param?? Is there a better approach to do that or is this even possible? Thx

Suffragan answered 8/1, 2010 at 11:9 Comment(1)
https://mcmap.net/q/189979/-how-to-send-longer-emails-from-a-chrome-extension See the answer above for majority of the code written for you. It's setup to be a chrome extension.Deathlike
A
6

@Pekka's response is good for a general mailto, but to get a Gmail compose window pre-filled, you need to use a URL like the following : http://mail.google.com/mail/?view=cm&fs=1&tf=1&[email protected]&[email protected]&[email protected]&su=SUBJECT&body=BODY -- with your parameters URL-encoded.

But be careful that you don't go beyond Google's character limit or you'll get a "414 - Request-URI Too Large" error, as explained in this StackOverflow question: Prefilling large volumes of body text in GMAIL compose getting a Request URI too long error

Astrodome answered 16/6, 2010 at 16:1 Comment(0)
U
1

To automatically open gmail in new tab and populate the fields:

The URL should be, https://mail.google.com/mail/?view=cm&fs=1&[email protected]&su=${subject}&body=${message}

Example:

const subject = `${formData.fullName} - ${formData.subject}`
const message = `${formData.message}`
const mailtoLink = `https://mail.google.com/mail/?view=cm&fs=1&[email protected]&su=${subject}&body=${message}`
      window.open(mailtoLink, '_blank') // this would open gmail in new link

Note: For the subject, the query param subject didn't work as suggested in most of the answers, but su worked for me.

Undergrowth answered 27/3 at 18:26 Comment(0)
H
0

Check this article.

mailto:[email protected]?subject=Hi!&body=Hi!

You can even specify headers, I didn't know that.

Hydroxy answered 8/1, 2010 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.