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
@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
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.
Check this article.
mailto:[email protected]?subject=Hi!&body=Hi!
You can even specify headers, I didn't know that.
© 2022 - 2024 — McMap. All rights reserved.