GMail Mailto Handler

How to enable the mailto links to automatically load into GMail. Note, Google does not currently have an automated method for achieving this, so I created my own.

Source files: Source Files

Add these steps into a sequencing file.

Step 1 – kill the chrome.exe process

Step 2 – apply reg key

Reg File

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\mailto]
“URL Protocol”=””

[HKEY_CURRENT_USER\Software\Classes\mailto\DefaultIcon]
@=”C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe,0″

[HKEY_CURRENT_USER\Software\Classes\mailto\shell]
@=”open”

[HKEY_CURRENT_USER\Software\Classes\mailto\shell\open]

[HKEY_CURRENT_USER\Software\Classes\mailto\shell\open\command]
@=”\”C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\” — \”%1\””

[HKEY_CURRENT_USER\Software\Classes\mailto\shell\open\ddeexec]
@=””

Step 3 – Install the handler.exe – which installs the extension and reg keys

Step 4 – Run VBScript

VBScript File

‘THIS ENABLES THE MAILTO HANDLER IN GMAIL
‘MAKES UPDATE TO THE PREFERENCE FILE LOCATED HERE C:\USERS\%USERNAME%\APPDATA\LOCAL\GOOGLE\CHROME\USER DATA\DEFAULT

‘on error resume next

dim filter1, strLine

Set objShell = CreateObject(“Wscript.Shell”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)

Const ForReading = 1
Const ForWriting = 2

‘user profile – dynamic variable
UserProf=objShell.ExpandEnvironmentStrings(“%userprofile%”)

‘sets working directory
strCurrentDirectory = UserProf & “\AppData\Local\Google\Chrome\User Data\Default\”

‘sets doc to scan
varDocToScan = “Preferences”

‘sets filter
filter1 = chr(34) & “url” & chr(34) & “: ” & chr(34) & “https://mail.google.com/mail/?extsrc=mailto&url=%s” & chr(34)

Set objFile = objFSO.OpenTextFile(strCurrentDirectory & varDocToScan, ForReading)

‘CHECK TO SEE IF HANDLER HAS BEEN ENABLED AND MAIL IS ENABLED

Do Until objFile.AtEndofStream
strLine = objFile.Readline
strLine = trim(strLine)
if strLine = filter1 then
objFile.Close
Wscript.Quit(0)
end if
Loop

objFile.Close

‘PATCH PREFERENCES FILE
‘chrome must not be running while the preferences file gets patched
objShell.Run “taskkill.exe /f /im chrome.exe”,0,true
objShell.Run “taskkill.exe /f /im chrome.exe”,0,true

varFind = chr(34) & “countryid_at_install” & chr(34) & “: 21843,”
varReplace = chr(34) & “countryid_at_install” & chr(34) & “: 21843,” &_
chr(13) & chr(34) & “custom_handlers” & chr(34) & “: {” &_
chr(13) & chr(34) & “enabled” & chr(34) & “: true,” &_
chr(13) & chr(34) & “registered_protocol_handlers” & chr(34) & “: [ {” &_
chr(13) & chr(34) & “default” & chr(34) & “: true,” &_
chr(13) & chr(34) & “protocol” & chr(34) & “: ” & chr(34) & “mailto” & chr(34) & “,” &_
chr(13) & chr(34) & “title” & chr(34) & “: ” & chr(34) & “Mail” & chr(34) & “,” &_
chr(13) & chr(34) & “url” & chr(34) & “: ” & chr(34) & “https://mail.google.com/mail/?extsrc=mailto&url=%s” & chr(34) &_
chr(13) & “} ]” &_
chr(13) & “},”

Set objFile = objFSO.OpenTextFile(strCurrentDirectory & “\” & varDocToScan, ForReading)
strText = objFile.ReadAll
objFile.Close

strNewText = Replace(strText, varFind, varReplace)

Set objFile = objFSO.OpenTextFile(strCurrentDirectory & “\” & varDocToScan, ForWriting)
objFile.WriteLine strNewText
objFile.Close

objShell.Run chr(34) & “C:\Program Files (x86)\Google\Chrome\Application\chrome.exe” & chr(34) & “–restore-last-session”,9,false
WScript.Quit(0)

Reg File

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\mailto]
“URL Protocol”=””

[HKEY_CURRENT_USER\Software\Classes\mailto\DefaultIcon]
@=”C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe,0″

[HKEY_CURRENT_USER\Software\Classes\mailto\shell]
@=”open”

[HKEY_CURRENT_USER\Software\Classes\mailto\shell\open]

[HKEY_CURRENT_USER\Software\Classes\mailto\shell\open\command]
@=”\”C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\” — \”%1\””

[HKEY_CURRENT_USER\Software\Classes\mailto\shell\open\ddeexec]
@=””

email me