I found out that in order to open a Gmail compose screen you'd have to be logged in and open the following link:
https://mail.google.com/a/domain/?view=cm&fs=1&tf=1&source=mailto&to=WHOEVER%40COMPANY.COM&su=SUBJECTHERE&cc=WHOEVER%40COMPANY.COM&bcc=WHOEVER%40COMPANY.COM&body=PREPOPULATEDBODY
Replacing the variables fills in the corresponding places on the compose form. However if I want to enter into the body multiline text or line breaks its just 开发者_运维知识库not working even if I urlencode it. Any ideas here?
Check that your UrlEncode method really translates newlines into "%0a". Here's an example of a 2-line email body:
https://mail.google.com/mail/?view=cm&ui=2&tf=0&fs=1&to=WHOEVER%40COMPANY.COM&su=SUBJECTHERE&body=LINE1%0aLINE2
Gmail has support for what HTML5's registerProtocolHandler() emits.
Example:
var compose = "https://mail.google.com/mail/?extsrc=mailto&url=" + encodeURIComponent("mailto:?subject=test");
That's what Gmail expects you to use. Modify the beginning for the domain-specific compose URI of course.
However, that loads the compose form by itself (not integrated with the inbox page). So, if you want the compose form integrated into the inbox page, you need to load:
"https://mail.google.com/mail/?compose=1&view=cm&fs=1&to=1&su=2&body=3&cc=4&bcc=5"
instead. But, that requires you to parse the mailto URI first to get the hfvalues and fix their percent-encoding to make sure they're fit to send in an HTTP URI. See below for more info on that.
Now, what Gmail does with the HTML5 compose URI is percent-decode the url param to get the mailto URI. Then, it parses the mailto URI to get the hfvalues. Then, it uses those hfvalues to build a URI like the inbox-integrated one and redirects you to it.
The problem with Gmail's HTML5 method is that it doesn't percent-encode '+' characters in the hfvalues to "%2B". The end result of this is that '+' characters in the mailto URI (they're not spaces in a mailto URI) come out as spaces in the Gmail compose form.
To work around the Gmail bug, you just do:
var compose = "https://mail.google.com/mail/?extsrc=mailto&url=" + encodeURIComponent("mailto:?subject=test".replace(/\+/g, "%2B"));
instead.
The bug was reported years ago, but Gmail refuses to fix it.
As you should also see, for the inbox-integrated compose URI, if you had the mailto URI "mailto:?subject=1+2", you need to make sure that you emit su=1%2B2 in the compose URI and not su=1+2. The latter will cause a space to be in the subject field instead of '+'. This part isn't a bug with Gmail. That's just how HTTP works.
You can see the source of my Gmail Compose Extension for Opera (unzip it) to see how I do the HTML5 way. It's very simple. But, it doesn't contain the + to %2B workaround though.
However, you can see the newer version of the extension that I'm testing (just need someone to test the domain-specific option in preferences) for more advanced handling. This one uses my custom, generic mailto URI parser to normalize the mailto URI and its hfvalues to handle the '+' case, unsafe characters and duplicates hfvalues. It also offers an option to choose whether you want to use the HTML5 compose URI or not.
You can also take a look at this User JS script for Opera for how to do things.
For the duplicate hfvalue issue mentioned earlier and other mailto URI stuff, see my mailto URI spec, which was used for research and feedback for RFC6068.
Note: Just because the Gmail user has rich text editing turned on, that doesn't mean that Gmail will accept HTML markup in the compose URI and treat it as such. It's all interpreted as text.
I used standard javascript encodeURIComponent() for encoding multiline body. It worked.
Also those who want to prepopulate generic gmail and not app domain specific account, use this URL instead:
https://mail.google.com/?view=cm&fs=1&tf=1&....
Thanks for that tip. One thing that hasn't been specified in other replies is that if you're logged into Gmail with multiple accounts, like a personal account and a professional one with Google Apps, using https://mail.google.com/a/domain.com/
instead of https://mail.google.com/mail/
allows you to specify which mailbox to use for sending the message. Otherwise Gmail just loads the account you logged-in first.
At present (February 2014), to prepopulate the compose screen with to and subject fields, use:
https://mail.google.com/mail/?&v=b&cs=wh&to=alias@domain.com&subject=subject%20goes%20here
Note: cs=wh
is significant, as the compose hyperlink uses cs=b
, which doesn't autopopulate.
Another limitation is that GET requests are limited to a certain number of characters so trying to use the MAILTO + GET params method won't work for larger pieces of content. Has anyone found another way to push larger content to a new Compose window via some sort of web request?
From what I can tell this will be difficult since the mailto is actually a browser action correct?
精彩评论