Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.68 KB | None | 0 0
  1. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_UseX64=y
  3. #AutoIt3Wrapper_Res_SaveSource=y
  4. #AutoIt3Wrapper_Res_Language=1033
  5. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  6. ; *** Start added by AutoIt3Wrapper ***
  7. #include <AutoItConstants.au3>
  8. ; *** End added by AutoIt3Wrapper ***
  9. ; *** Start added by AutoIt3Wrapper ***
  10. #include <MsgBoxConstants.au3>
  11. ; *** End added by AutoIt3Wrapper ***
  12. #cs ----------------------------------------------------------------------------
  13.  
  14. AutoIt Version: 3.3.15.0 (Beta)
  15. Author: William Higgs
  16.  
  17. Script Function:
  18. Provides a graphical user interface for the command line utility "Cmail", which lets one send emails via command line. I wrote this
  19. specificially to reduced the ammount of time needed to send messages to potential employers.
  20.  
  21. #ce ----------------------------------------------------------------------------
  22.  
  23. ; Script Start - Add your code below here
  24. #include <ButtonConstants.au3>
  25. #include <EditConstants.au3>
  26. #include <GUIConstantsEx.au3>
  27. #include <StaticConstants.au3>
  28. #include <WindowsConstants.au3>
  29. #include <File.au3>
  30. #include <Array.au3>
  31. #include <GuiEdit.au3>
  32. #include <WordEx.au3>
  33. #include <GuiListBox.au3>
  34. #include <Constants.au3>
  35.  
  36. Global $trans = False
  37. _WordErrorHandlerRegister()
  38.  
  39. Global $oWordApp = _WordCreate("", 0, 0, 0)
  40. Global $oDoc = $oWordApp.ActiveDocument
  41. Global $oRange = $oDoc.Range
  42. Global $oSpellCollection, $oAlternateWords
  43. HotKeySet ( "^d", "stylish" )
  44. $Form2 = GUICreate("Cmail email sender", 406, 462, 345, 299, BitOR($GUI_SS_DEFAULT_GUI,$DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
  45. Global $handle = WinGetHandle ( $Form2 )
  46. $Input1 = GUICtrlCreateInput("", 70, 32, 273, 21)
  47. $Input2 = GUICtrlCreateInput("", 74, 88, 265, 21)
  48. $Label1 = GUICtrlCreateLabel("Email Address", 128, 0, 130, 29)
  49. GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
  50. $Label2 = GUICtrlCreateLabel("Job Title", 163, 56, 79, 29)
  51. GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
  52. $Checkbox1 = GUICtrlCreateCheckbox("Resume", 64, 112, 89, 25)
  53. $Checkbox2 = GUICtrlCreateCheckbox("References", 264, 112, 81, 25)
  54. $Checkbox3 = GUICtrlCreateCheckbox("Character sheet", 64, 144, 105, 25)
  55. $Checkbox4 = GUICtrlCreateCheckbox("Misc", 264, 144, 81, 25)
  56. $Label4 = GUICtrlCreateLabel("Subject (optional)", 124, 168, 157, 29)
  57. GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
  58. $Input3 = GUICtrlCreateInput("", 32, 200, 337, 21)
  59. $Label3 = GUICtrlCreateLabel("Message (optional)", 116, 224, 172, 29)
  60. GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
  61. $Edit1 = GUICtrlCreateEdit("", 32, 256, 345, 153, BitOR($ES_WANTRETURN, $WS_VSCROLL))
  62. $Button1 = GUICtrlCreateButton("Send", 48, 416, 113, 33, $BS_NOTIFY)
  63. GUICtrlSetCursor (-1, 0)
  64. $Button2 = GUICtrlCreateButton("Cancel", 216, 416, 105, 33, $BS_NOTIFY)
  65. GUICtrlSetCursor (-1, 0)
  66. $aRect = _GUICtrlEdit_GetRECT($Edit1)
  67. $aRect[0] += 10
  68. $aRect[1] += 10
  69. $aRect[2] -= 10
  70. $aRect[3] -= 10
  71. _GUICtrlEdit_SetRECT($Edit1, $aRect)
  72. $Form1 = GUICreate("Spell check", 345, 251, 302, 218)
  73. Global $handle2 = WinGetHandle ( $Form1 )
  74. $ListBox1 = GUICtrlCreateList("", 8, 8, 137, 149, $LBS_NOTIFY + $WS_VSCROLL )
  75. $ListBox2 = GUICtrlCreateList("", 200, 8, 137, 149, $LBS_NOTIFY + $WS_VSCROLL )
  76. $Button3 = GUICtrlCreateButton("Send", 32, 201, 75, 25, $BS_NOTIFY)
  77. GUICtrlSetCursor (-1, 0)
  78. $Button4 = GUICtrlCreateButton("&Cancel", 240, 201, 75, 25, $BS_NOTIFY)
  79. GUICtrlSetCursor (-1, 0)
  80. $Button5 = GUICtrlCreateButton("Correct spelling", 128, 201, 83, 25, $BS_NOTIFY)
  81. GUICtrlSetState(-1, $GUI_DISABLE)
  82. GUICtrlSetCursor (-1, 0)
  83. GUISetState( @SW_DISABLE, $Form1 )
  84. GUISetState( @SW_SHOW, $Form2 )
  85. While 1
  86. Global $nMsg = GUIGetMsg(1)
  87. Switch $nMsg[1]
  88. Case $Form2
  89. Switch $nMsg[0]
  90. Case $GUI_EVENT_CLOSE
  91. _Exit()
  92. Case $Button1
  93. If _GUICtrlEdit_GetTextLen ( $Edit1 ) = 0 Then
  94. _GUICtrlEdit_SetText ( $Edit1, "Hello," & @CRLF & "My name is William Higgs, and I am interested in applying for the " & GUICtrlRead ( $Input2 ) & " position that was posted online. Attached is my resume, which also has my contact information. Please reach out to me at your earliest convenience should you want to speak to me concerning the position. Thank you." & @CRLF & "William Higgs" )
  95. EndIf
  96. _SpellCheck ()
  97. Case $Button2
  98. _Exit()
  99. EndSwitch
  100. Case $Form1
  101. Switch $nMsg[0]
  102. Case $GUI_EVENT_CLOSE
  103. GUISetState ( @SW_HIDE, $Form1 )
  104. GUISetState ( @SW_DISABLE, $Form1 )
  105. GUISwitch ( $Form2 )
  106. GUISetState ( @SW_ENABLE, $Form2 )
  107. GUISetState ( @SW_SHOW, $Form2 )
  108. Case $ListBox1
  109. _SpellingSuggestions()
  110. Case $ListBox2
  111. GUICtrlSetState($Button5, $GUI_ENABLE)
  112. Case $Button3
  113. SendMessage ()
  114. Case $Button4
  115. GUISetState ( @SW_HIDE, $Form1 )
  116. GUISetState ( @SW_DISABLE, $Form1 )
  117. GUISwitch ( $Form2 )
  118. GUISetState ( @SW_ENABLE, $Form2 )
  119. GUISetState ( @SW_SHOW, $Form2 )
  120. Case $Button5
  121. _ReplaceWord()
  122. EndSwitch
  123. EndSwitch
  124. WEnd
  125. Func stylish ()
  126. $thestyle = GUIGetStyle ( $handle )
  127. If $trans = False Then
  128. GUISetStyle ( -1, $thestyle[1] + 32, $handle )
  129. WinSetTrans ( $handle, "", 170 )
  130. $trans = True
  131. Else
  132. GUISetStyle ( -1, $thestyle[1] - 32, $handle )
  133. WinSetTrans ( $handle, "", 255 )
  134. $trans = False
  135. EndIf
  136. EndFunc
  137. Func GetHoveredHwnd()
  138. Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
  139. If IsArray($iRet) Then Return HWnd($iRet[0])
  140. Return SetError(1, 0, 0)
  141. EndFunc
  142. Func _SpellCheck()
  143. Local $sText, $tText, $sWord
  144.  
  145. $sText = GUICtrlRead($Edit1)
  146. $oRange = $oWordApp.ActiveDocument.Range
  147. $oRange.Delete
  148. $oRange.InsertAfter($sText)
  149. _SetLanguage()
  150.  
  151. $oSpellCollection = $oRange.SpellingErrors
  152. If $oSpellCollection.Count > 0 Then
  153. If BitAND ( WinGetState ( $handle ), 2 ) Then
  154. If $trans = True Then
  155. stylish ()
  156. EndIf
  157. GUISetState ( @SW_DISABLE, $Form2 )
  158. GUISetState ( @SW_HIDE, $Form2 )
  159. GUISwitch ( $Form1 )
  160. GUISetState ( @SW_SHOW, $Form1 )
  161. GUISetState ( @SW_ENABLE, $Form1 )
  162. EndIf
  163.  
  164. ;
  165. _GUICtrlListBox_ResetContent($ListBox1)
  166. _GUICtrlListBox_ResetContent($ListBox2)
  167. GUICtrlSetState($Button5, $GUI_DISABLE)
  168. For $i = 1 To $oSpellCollection.Count
  169. $sWord = $oSpellCollection.Item($i).Text
  170. _GUICtrlListBox_AddString($ListBox1, $sWord)
  171. Next
  172. GUICtrlSetData($Edit1, $oRange.Text)
  173. Else
  174. SendMessage ()
  175. EndIf
  176. EndFunc ;==>_SpellCheck
  177.  
  178. Func _SpellingSuggestions()
  179. Local $iWord, $sWord
  180. ;
  181. _GUICtrlListBox_ResetContent($ListBox2)
  182. GUICtrlSetState($Button5, $GUI_DISABLE)
  183.  
  184. $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
  185. $sWord = $oSpellCollection.Item($iWord).Text
  186.  
  187. $oAlternateWords = $oWordApp.GetSpellingSuggestions($sWord)
  188. If $oAlternateWords.Count > 0 Then
  189. For $i = 1 To $oAlternateWords.Count
  190. _GUICtrlListBox_AddString($ListBox2, $oAlternateWords.Item($i).Name)
  191. Next
  192. Else
  193. _GUICtrlListBox_AddString($ListBox2, "No suggestions.")
  194. EndIf
  195. EndFunc ;==>_SpellingSuggestions
  196.  
  197. Func _HighlightWord()
  198. Local $sText, $iWord, $sWord, $iEnd, $iStart
  199. ;
  200. $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
  201. $sWord = $oSpellCollection.Item($iWord).Text
  202. $sText = $oRange.Text
  203.  
  204. $iStart = ($oSpellCollection.Item($iWord).Start)
  205. $iEnd = ($oSpellCollection.Item($iWord).End)
  206. _GUICtrlEdit_SetSel($Edit1, $iStart, $iEnd)
  207. EndFunc ;==>_HighlightWord
  208.  
  209. Func _ReplaceWord()
  210. Local $iWord, $iNewWord, $sWord, $sNewWord, $sText, $sNewText
  211. ;
  212. $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
  213. $iNewWord = _GUICtrlListBox_GetCurSel($ListBox2) + 1
  214. If $iWord == $LB_ERR Or $iNewWord == $LB_ERR Then
  215. MsgBox(48, "Error", "You must first select a word to replace, then a replacement word.")
  216. Return
  217. EndIf
  218. $oSpellCollection.Item($iWord).Text = $oAlternateWords.Item($iNewWord).Name
  219.  
  220. GUICtrlSetData($Edit1, $oRange.Text)
  221.  
  222. _SpellCheck()
  223.  
  224. GUICtrlSetState($Button5, $GUI_DISABLE)
  225. EndFunc ;==>_ReplaceWord
  226.  
  227. Func _SetLanguage()
  228. $sLang = "English"
  229. If $sLang <> "" Then
  230. $oWordApp.CheckLanguage = False
  231. $WdLangID = Number(1033)
  232.  
  233. If $WdLangID Then
  234. With $oRange
  235. .LanguageID = $WdLangID
  236. .NoProofing = False
  237. EndWith
  238. EndIf
  239. Else
  240. $oWordApp.CheckLanguage = True
  241. EndIf
  242. EndFunc ;==>_SetLanguage
  243.  
  244. Func SendMessage ()
  245. If BitAND ( WinGetState ( $handle2 ), 2 ) Then
  246. GUISetState ( @SW_HIDE, $Form1 )
  247. GUISetState ( @SW_DISABLE, $Form1 )
  248. GUISwitch ( $Form2 )
  249. GUISetState ( @SW_ENABLE, $Form2 )
  250. GUISetState ( @SW_SHOW, $Form2 )
  251. EndIf
  252. $body = GUICtrlRead ( $Edit1 )
  253. _GUICtrlEdit_SetText ( $Edit1, "" )
  254.  
  255. $attach = Null
  256. If GUICtrlRead ( $Checkbox1 ) = 1 Then
  257. $attach = $attach & '"C:\Users\whiggs\OneDrive\Documents\Matt_Real_Resume(revised)_career.docx" '
  258. EndIf
  259. If GUICtrlRead ( $Checkbox2 ) = 1 Then
  260. $attach = $attach & '"C:\Users\whiggs\OneDrive\Documents\Professional_references_shorter.docx" '
  261. EndIf
  262. If GUICtrlRead ( $Checkbox3 ) = 1 Then
  263. $attach = $attach & '"C:\Users\whiggs\OneDrive\Documents\__JOB_STRENGTHS.docx" "C:\Users\whiggs\OneDrive\Documents\3CiConsultant-Mindset-Completed.pdf" '
  264. EndIf
  265. If GUICtrlRead ( $Checkbox4 ) = 1 Then
  266. $attach = $attach & '"C:\Users\whiggs\OneDrive\Documents\Copy_of_Will.xlsx" "C:\Users\whiggs\OneDrive\Documents\Copy_of_Will_(Nov).xlsx" "C:\Users\whiggs\OneDrive\Documents\Copy_of_Will_Scorecard_2015.xlsx" "C:\Users\whiggs\OneDrive\Documents\example1.pdf" "C:\Users\whiggs\OneDrive\Documents\example2.pdf" "C:\Users\whiggs\OneDrive\Documents\example3.pdf" '
  267. EndIf
  268. If GUICtrlRead ( $Checkbox1 ) = 1 Or GUICtrlRead ( $Checkbox2 ) = 1 Or GUICtrlRead ( $Checkbox3 ) = 1 Or GUICtrlRead ( $Checkbox4 ) = 1 Then
  269. $attach = StringStripWS ( $attach, 2 )
  270. EndIf
  271.  
  272. ;$attach = StringStripCR ( $attach )
  273. If StringLen ( GUICtrlRead ( $Input3 ) ) = 0 Then
  274. $subject = "Interested in the posted position: " & GUICtrlRead ( $Input2 )
  275. Else
  276. $subject = GUICtrlRead ( $Input3 )
  277. EndIf
  278. If $attach <> Null Then
  279. $split = StringSplit ( $attach, ' ' )
  280. _ArrayDisplay ( $split )
  281. If @error Then
  282. SetError ( 0 )
  283. $attach = '-a:' & $attach & ' '
  284. Else
  285. $attach = Null
  286. For $i = 1 To $split[0] Step 1
  287. $attach = $attach & '-a:' & $split[$i] & ' '
  288. Next
  289. EndIf
  290. EndIf
  291. If $attach = Null Then
  292. $proc = Run ( 'CMail -from:whiggs.ITPRO@gmail.com:"William Higgs" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" -host:whiggs.ITPRO@gmail.com:passwordhere@smtp.gmail.com:587 -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
  293. Else
  294. $proc = Run ( 'CMail -from:whiggs.ITPRO@gmail.com:"William Higgs" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" ' & $attach & '-host:whiggs.ITPRO@gmail.com:passwordhere@smtp.gmail.com:587 -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
  295. EndIf
  296.  
  297. ProcessWaitClose ( $proc )
  298. $text = StdoutRead ( $proc )
  299. ClipPut ( $text )
  300. MsgBox($MB_OK + $MB_ICONASTERISK,"Sent!","Message Sent!!")
  301. EndFunc
  302.  
  303. Func _Exit()
  304. _WordQuit($oWordApp, 0)
  305. Exit
  306. EndFunc ;==>_Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement