Skip to content

Instantly share code, notes, and snippets.

Created September 13, 2015 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/93349f26755df54ab525 to your computer and use it in GitHub Desktop.
Save anonymous/93349f26755df54ab525 to your computer and use it in GitHub Desktop.
AHK script to be Windows default mailto app, forwarding to Gmail
; Copied from http://www.autohotkey.com/board/topic/39551-change-the-default-mailto-to-gmail/
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
total = %1%
;~ If no paramter is given when the run of it, it registers itself as the default mailto
StringLen, pos, 1
if (pos = 0) {
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\Classes\mailto\shell\open\command,, "%A_ScriptFullPath%" `%1
ExitApp
}
;~ Splits the mail adress from all the other paramters!
StringSplit, part, total, ?
mail = %part1%
others = %part2%
;~ MsgBox, %total%`n%mail%`n%others%
;~ Splits up to 4 paramters that maybe present (subject,body,cc,bcc)
StringSplit, part, others, &
;~ MsgBox, %total%`nmail=%mail%`npart1=%part1%`npart2=%part2%`npart3=%part3%`npart4=%part4%
;~ Tries to find in each of the 4 paramters the subject,body,cc,bcc "text"
StringGetPos, pos, part1, subject=
if pos = 0
subject = %part1%
StringGetPos, pos, part1, body=
if pos = 0
body = %part1%
StringGetPos, pos, part1, cc=
if pos = 0
cc = %part1%
StringGetPos, pos, part1, bcc=
if pos = 0
bcc = %part1%
StringGetPos, pos, part2, subject=
if pos = 0
subject = %part2%
StringGetPos, pos, part2, body=
if pos = 0
body = %part2%
StringGetPos, pos, part2, cc=
if pos = 0
cc = %part2%
StringGetPos, pos, part2, bcc=
if pos = 0
bcc = %part2%
StringGetPos, pos, part3, subject=
if pos = 0
subject = %part3%
StringGetPos, pos, part3, body=
if pos = 0
body = %part3%
StringGetPos, pos, part3, cc=
if pos = 0
cc = %part3%
StringGetPos, pos, part3, bcc=
if pos = 0
bcc = %part3%
StringGetPos, pos, part4, subject=
if pos = 0
subject = %part4%
StringGetPos, pos, part4, body=
if pos = 0
body = %part4%
StringGetPos, pos, part4, cc=
if pos = 0
cc = %part4%
StringGetPos, pos, part4, bcc=
if pos = 0
bcc = %part4%
;~ Removes the unwanted stuff as "mailto:" or "subject=", ... from the strings!
StringTrimLeft, mail, mail, 7
StringTrimLeft, subject, subject, 8
StringTrimLeft, body, body, 5
StringTrimLeft, cc, cc, 3
StringTrimLeft, bcc, bcc, 4
;~ MsgBox, http://mail.google.com/mail/?view=cm&fs=1&tf=1&su=%subject%&to=%mail%&body=%body%&cc=%cc%&bcc=%bcc%&fs=1
;~ "Sends the mail" with Google to the default browser
Run, http://mail.google.com/mail/?view=cm&fs=1&tf=1&su=%subject%&to=%mail%&body=%body%&cc=%cc%&bcc=%bcc%&fs=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment