Gmail instead of Outlook mailto:
Google is ubiquitous. Everyone knows Google and uses Google. In fact its become a noun, verb and sometimes as adjective, too. Gmail which was more restricted to personal usage has aggressively made way into the corporate landscape. The cloud adoption has fast-tracked the usage of Corporate Gmail account instead of the traditional thick clients especially Outlook.
In most of our applications the APIs have been adapted to trigger Outlook email. The default URLHelper control triggers the Outlook email. Now, I was stuck with a situation where I had to move the behavior from mailto – Outlook to Gmail.
Some of the options explored where to modify the chrome default handler to Gmail. It Didn’t work for me.
Then, I stumbled upon a href- URL which can be built to trigger the gmail. This seemed like a easier way to adapt the code. I had to replace the triggerEmail default function with URLHelper.
My approach was simple:
- Prepare the URL to trigger the Gmail.
- In the URLHelper, use the redirect method
- Pass the URL to the redirect method. Thats it!
The code snippet is as follows:
- URL to trigger the GMAIL
// Prepare the Email URL var sGmailUrl = "https://mail.google.com/mail?view=cm&tf=0" + (emailTo ? ("&to=" + emailTo) : "") + (emailCC ? ("&cc=" + emailCC) : "") + (emailSubject ? ("&su=" + emailSubject) : "") + (emailBody ? ("&body=" + emailBody) : "");
You can pass the To address, cc and bcc address, email body and subject to the URL.
2 and 3. In the URLHelper, use the redirect method. The boolean value true will open the compose window in a separate tab instead of the page in which you are triggering the action.
That is all for now.
Please share your queries or feedback’s in the comments section.
P.S.: The opinions and content shared in my blogs are purely personal and any resemblance is co-incidental.