开发者

URL to compose a message in Gmail (with full Gmail interface and specified to, bcc, subject, etc.)

开发者 https://www.devze.com 2023-03-17 04:02 出处:网络
I found a post that provides an example for a link which opens just a compose message window. However, I would like it to open a window with the full开发者_运维百科 Gmail interface but ready to compos

I found a post that provides an example for a link which opens just a compose message window. However, I would like it to open a window with the full开发者_运维百科 Gmail interface but ready to compose a new message.

Of course this works:

https://mail.google.com/mail/u/0/#compose

But, I would also like to add a subject, to, bcc, etc. I tried something like the following, but to no avail:

https://mail.google.com/mail/?to=inbox@example.com&bcc=admin@example.com&subject=Hey#compose

Any ideas? Thanks.


This seems to work (for now):

https://mail.google.com/mail/?view=cm&fs=1&to=someone@example.com&su=SUBJECT&body=BODY&bcc=someone.else@example.com


Bookmarking this URL should give you a full-screen compose window, without any distractions:

https://mail.google.com/mail/?view=cm&fs=1&tf=1

Additionally, if you want to be future-proof (see for instance how other URLs in this question stopped working) you can bookmark a link to:

mailto:

It will open your default email client and you probably already have Gmail configured for that purpose.


I thought I'd try and consolidate the information from several good answers and comments and provide some additional information. Examples first then background and explanation of terminology below.

N.B. All links will fall back to the default account if there is no match

Simple Compose Link

Opens the inbox with a compose window in the bottom right

  • Default account:
    https://mail.google.com/mail/#compose
  • Specific account by index (second in this example):
    https://mail.google.com/mail/u/1/#compose
  • Specific account by email address (lee@example.org in this example):
    https://mail.google.com/mail/u/lee@example.org/#compose
  • Any account from specific domain (example.edu in this example):
    https://mail.google.com/a/example.edu/mail/#compose
  • From specific delegated mailbox (id abcd1234efgh5678 in this example):
    https://mail.google.com/mail/d/abcd1234efgh5678/#compose
  • From specific delegated mailbox belonging to non-default account (id 1234efgh5678ijkl, fourth user):
    https://mail.google.com/mail/u/3/d/1234efgh5678ijkl/#compose

Each example above automatically redirects from #compose to #inbox?compose=new. You can use either URL.

Custom compose links

Include a to address, subject, body, cc and bcc by opening the Compose Message (cm) view directly. This opens the compose message view fullscreen (even without fs=1 parameter). May struggle with some special characters in the URL.

  • Default account:
    https://mail.google.com/mail/?view=cm&to=morgan@example.com&su=SUBJECT&body=BODY&bcc=dakota@example.com
  • Specific account by index (second in this example):
    https://mail.google.com/mail/u/1/?view=cm&to=morgan@example.com&su=SUBJECT&body=BODY&bcc=dakota@example.com
  • Specific account by email address (lee@example.org in this example):
    https://mail.google.com/mail/u/lee@example.org/?view=cm&to=morgan@example.com&su=SUBJECT&body=BODY&bcc=dakota@example.com
  • Any account from specific domain (example.edu in this example):
    https://mail.google.com/a/example.edu/mail/?view=cm&to=morgan@example.com&su=SUBJECT&body=BODY&bcc=dakota@example.com
  • From specific delegated mailbox (id abcd1234efgh5678 in this example):
    https://mail.google.com/mail/d/abcd1234efgh5678/?view=cm&to=morgan@example.com&su=SUBJECT&body=BODY&bcc=dakota@example.com
  • From specific delegated mailbox belonging to non-default account (id 1234efgh5678ijkl, fourth user):
    https://mail.google.com/mail/u/3/d/1234efgh5678ijkl/?view=cm&to=morgan@example.com&su=SUBJECT&body=BODY&bcc=dakota@example.com

Complex compose links

Anything you can put in a mailto: link can be passed to Gmail. You need to URL encode* the mailto link first. This takes care of accented letters and other special characters that URLs can choke on:

mailto:morgan@example.com?subject=SUBJECT&body=BODY&bcc=dakota@example.com
  v  v  v  v  v  v 
mailto%3Amorgan%40example.com%3Fsubject%3DSUBJECT%26body%3DBODY%26bcc%3Ddakota%40example.com
  • Default account:
    https://mail.google.com/mail/?extsrc=mailto&url=mailto%3Amorgan%40example.com%3Fsubject%3DSUBJECT%26body%3DBODY%26bcc%3Ddakota%40example.com
  • Specific account by index (second in this example):
    https://mail.google.com/mail/u/1/?extsrc=mailto&url=mailto%3Amorgan%40example.com%3Fsubject%3DSUBJECT%26body%3DBODY%26bcc%3Ddakota%40example.com
  • Specific account by email address (lee@example.org in this example):
    https://mail.google.com/mail/u/lee@example.org/?extsrc=mailto&url=mailto%3Amorgan%40example.com%3Fsubject%3DSUBJECT%26body%3DBODY%26bcc%3Ddakota%40example.com
  • Any account from specific domain (example.edu in this example):
    https://mail.google.com/a/example.edu/mail/?extsrc=mailto&url=mailto%3Amorgan%40example.com%3Fsubject%3DSUBJECT%26body%3DBODY%26bcc%3Ddakota%40example.com
  • From specific delegated mailbox (id abcd1234efgh5678 in this example):
    https://mail.google.com/mail/d/abcd1234efgh5678/?extsrc=mailto&url=mailto%3Amorgan%40example.com%3Fsubject%3DSUBJECT%26body%3DBODY%26bcc%3Ddakota%40example.com
  • From specific delegated mailbox belonging to non-default account (id 1234efgh5678ijkl, fourth user):
    https://mail.google.com/mail/u/3/d/1234efgh5678ijkl/?extsrc=mailto&url=mailto%3Amorgan%40example.com%3Fsubject%3DSUBJECT%26body%3DBODY%26bcc%3Ddakota%40example.com

*More information on URL Encoding / Percent Encoding on Wikipedia. At the time of writing, urlencoder.io allows you to encode online and also has links to blog articles on how to URL Encode using a few common languages.

Background and Definitions

  • You can log in to multiple Gmail and/or Google Workspace accounts.
  • The first account you log into in a fresh browser becomes your default account.
  • The default account can vary for you if you use different browsers or browser profiles. It can also change if you sign out, remove all accounts and sign back in in a different order.
  • If you sign in to multiple accounts they are indexed in order of sign in. The default account has an index of zero. Navigating to https://mail.google.com/mail/#inbox will usually redirect you to your default account (index zero) if you are signed in to more than one account: https://mail.google.com/mail/u/0/#inbox
  • You can specify a Google Workspace domain by inserting /a/<domain> before /mail (whereas user index /u/<index> goes after /mail). This can be useful when you are providing a link internally in a company and you want the link to compose a new email in their work account (regardless of what order they signed in to their various accounts with)
  • You can compose a message from a delegated mailbox only if you know the delegation ID (and the user index of the account with delegate permissions if not the default account):
    https://mail.google.com/mail/d/ALGkd7w86mZOVigdDwK63uDpfMPlA2GJN7qSc4P7idKz7ffqTN0L/#compose OR
    https://mail.google.com/mail/u/0/d/ALGkd7w86mZOVigdDwK63uDpfMPlA2GJN7qSc4P7idKz7ffqTN0L/#compose OR, for user number 4,
    https://mail.google.com/mail/u/3/d/ALGkd7w86mZOVigdDwK63uDpfMPlA2GJN7qSc4P7idKz7ffqTN0L/#compose


The GMail web client supports mailto: links

For regular @gmail.com accounts: https://mail.google.com/mail/?extsrc=mailto&url=...

For G Suite accounts on domain gsuitedomain.com: https://mail.google.com/a/gsuitedomain.com/mail/?extsrc=mailto&url=...

... needs to be replaced with a urlencoded mailto: link.

Demo: https://mail.google.com/mail/?extsrc=mailto&url=mailto%3A%3Fto%3Dsomeguy%40gmail.com%26bcc%3Dmyattorney%40gmail.com%2Cbuzzfeed%40gmail.com%26subject%3DHi%2520There%26body%3Dbody%2520goes%2520here

Learn more about mailto: links by reading RFC6068


It's worth pointing out that if you have multiple Gmail accounts, you may want to use the URL approach because you can customize which account to compose from.

e.g.

https://mail.google.com/mail/u/0/#inbox?compose=new   
https://mail.google.com/mail/u/1/#inbox?compose=new

Or if you know the email address you are sending from, replace the numeric index with the email address:

https://mail.google.com/mail/u/your@email.com/#inbox?compose=new


https://mail.google.com/mail/u/0/x/?&v=b&eot=1&pv=tl&cs=b

This link works for composing directly in m.gmail.com as mobile in a desktop browser. Why? It is really faster.


For Chrome:

  1. Set your email manager to Gmail

URL to compose a message in Gmail (with full Gmail interface and specified to, bcc, subject, etc.)

  1. Write mailto: in the address bar and press enter.

Easier:

  1. Edit search engines:

URL to compose a message in Gmail (with full Gmail interface and specified to, bcc, subject, etc.)

URL to compose a message in Gmail (with full Gmail interface and specified to, bcc, subject, etc.)

  1. Write mt and enter in address bar.


Many others have done an excellent job here giving a basic answer, especially Tobias Mühl. As mentioned, GMail's Api very closely matches the definition given by RFC2368 and RFC6068. This is true of the extended form of the mailto: links, but it's also true in the commonly-used forms found in the other answers. Of the five parameters, four are identical (such as to, cc, bcc and body) and one received only slight modification (su is gmail's version of subject).

If you want to know more about what you can do with mailTo gmail URLs, then these RFCs might be of help. Unfortunately, Google has not published any source themselves.

To clarify the parameters:

  • to - Email to who
  • su (gmail API) / subject (mailTo API) - Email Title
  • body - Email Body
  • bcc - Email Blind-Carbon Copy
  • cc - Email Carbon Copy address


The example URLs for standard gmail, above, return a google error.

The February 2014 post to thread 2583928 recommends replacing view=cm&fs=1&tf=1 with &v=b&cs=wh.

Note: It also no longer seems possible to autopopulate the mail body.


When you click on compose email in Gmail notice that the url changes from https://mail.google.com/mail/u/0/#inbox to https://mail.google.com/mail/u/0/#inbox?compose=new. Now when you enter say a email id xyz@gmail.com , the value for compose changes now the url became https://mail.google.com/mail/u/0/#inbox?compose=150b0f7ffb682642.

So this is working fine with my html hyperlink until the account is signed in, but if the account is not signed in it would take me the login page and when I enter the credentials somehow this compose value is lost and this does not work.


<a href="mailto:?subject=BlahBlah&body=Dear%20Name,%0D%0A%0D%0AI%20would%20like%20to%20take%20this%20pportunity%20to%20,%0D%0ABest%20regards">

I test this way for my website, and it's worked. After "mailto:" write your the email you want to receive info. "%20" means the letter space. "%0D%0A%" means new paragraph.

0

精彩评论

暂无评论...
验证码 换一张
取 消