danrim

Outlook examples 2

Sep 29th, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance, Force
  2.  
  3. ;https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem.actions
  4.  
  5. ;                               BASIC INTRO FOR OUTLOOK
  6. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  7. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  8. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  9. /*
  10. MailItem := ComObjActive("Outlook.Application").CreateItem(0) ; Create a new MailItem object
  11. ;~ MsgBox, % IsObject(MailItem) ; testing if it is an object
  12. MailItem.SendUsingAccount := Mail.Application.Session.Accounts.Item["[email protected]"] ; Assign which accont to use (can also use NameSpace)
  13. MailItem.BodyFormat := 2 ; Outllok Constants: 1=Text 2=HTML 3=RTF
  14. MailItem.TO :="" ; Seperate by ; if you want to have multiple
  15. MailItem.CC := ""
  16. MailItem.Subject := "Example subject line"
  17.  
  18. ;~ MailItem.Attachement.Add("B:\folder\folder2\AHK_BALL.jpg")
  19. ;~ MailItem.Importance := 2 ; 0=Low 1=normal 2=High
  20. ;~ MailItem.DeferredDeliveryTime := "1/6/12 10:40:00 AM"
  21. ;~ MailItem.OriginatorDeliveryReportRequest := 1 ;request a delivery Reciept
  22. ;~ MailItem.ReadReceiptRequested := ; Requesta read receipt
  23. Name := "Bob"
  24.  
  25. Body =
  26. ( Join comments
  27. <HTML>
  28.     <p>Hi there %Name%, </p> ; this is comment
  29.     <p>Just saying hello </p>
  30. </HTML>
  31. )
  32.  
  33. MailItem.HTMLBody := Body
  34. MailItem.Display
  35. ;~ MailItem.Close(0) ; Creates draft version in default folder
  36. ;~ MailItem.Send() ; Sends the email
  37.  
  38.  
  39. Return
  40. */
  41. ;                               PERSONALIZE EMAILS
  42. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  43. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  44. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  45. /*
  46. var =
  47. (
  48. Email   First_Name  Last_Name
  49. [email protected]     Jonas   Burbuliavicius
  50.  
  51. [email protected]   Petras  Slekys
  52. )
  53.  
  54. ; *********Use For Loop over var (variable) going line by line********************
  55. for i, row in Loopobj:=StrSplit(var,"`n") { ;Parse Var on each new line
  56.     IfEqual, i,1,continue ;Skip header row
  57.     ;~ IfLessOrEqual,i,4382, continue
  58.     IfEqual,row,,continue ; Skip loop if blank
  59.        
  60.     Menu, tray, tip, % i-1 " of " Loopobj.maxindex()-1 " : email is " StrSplit(row,"`t").1 ;Show progress on icon in system tray
  61. ;~ MsgBox, % StrSplit(row,"`t").1 A_Tab StrSplit(row,"`t").2 A_Tab StrSplit(row,"`t").3 ; demonstrate values
  62.  
  63.  
  64.     MailItem := ComObjActive("Outlook.Application").CreateItem(0) ; Create a new MailItem object
  65.     ;~ MsgBox, % IsObject(MailItem) ; testing if it is an object
  66.     MailItem.SendUsingAccount := Mail.Application.Session.Accounts.Item["[email protected]"] ; Assign which account to use (can also use NameSpace
  67.     MailItem.BodyFormat := 2 ; Outllok Constants: 1=Text 2=HTML 3=RTF
  68.     MailItem.TO :=StrSplit(row,"`t").1 ; Seperate by ; if you want to have multiple
  69.     MailItem.Subject := "Example subject line"
  70.  
  71.     Name := StrSplit(row,"`t").2
  72.     LastName := StrSplit(row,"`t").3
  73.  
  74.     Body =
  75.     ( Join comments
  76.     <HTML>
  77.         <p>Hi there %Name% %LastName% </p> ; this is comment
  78.         <p>Just saying hello </p>
  79.     </HTML>
  80.     )
  81.  
  82.     MailItem.HTMLBody := Body
  83.     MailItem.Display
  84.     MsgBox, pause
  85. } ; brackets of for loop
  86.  
  87.  
  88. ;~ MailItem.Close(0) ; Creates draft version in default folder
  89. ;~ MailItem.Send() ; Sends the email
  90. return
  91. */
  92.  
  93.  
  94. ;               PERSONALIZE EMAILS AND TAKE INFO FROM EXCEL DATABASE
  95. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  96. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  97. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  98. ; https://www.youtube.com/watch?v=cvZEE7v22wE
  99. ; time 32:49
  100.  
  101.  
  102.  
  103.  
  104. ; Su email susijes pavyzdys
  105. !Numpad1::
  106. subjectField := "This is Subject field"
  107. contentField := "This is my msg and content"
  108. Run, mailto:Rimantas.Danilevicius@cognizant.com?subject=%aaa%&body=%bbb%
  109. return
  110.  
  111. ;******************************************************************************************************************************************
  112. ;******************************************************************************************************************************************
  113. ;******************************************************************************************************************************************
  114.  
  115. mail := ComObjActive("Outlook.Application").GetNameSpace("MAPI").GetDefaultFolder[6]    ; Inbox
  116.  
  117. Loop % mail.Items.Count {                                                               ; Loop over emails
  118.     if Instr(mail.Items[A_Index].SenderName,"Google Alerts") {                          ; Filter emails to just being sent by Google Alerts
  119.     MsgBox % "To: " mail.Items[A_Index].To "`r`r"
  120.     . "Subject: `t" mail.Items[A_Index].Subject "`r`r"
  121.         . "Body: `t" mail.Items[A_Index].Body "`r`r"
  122.     }
  123. }
  124. return
  125.  
  126. ;******************************************************************************************************************************************
  127. ;******************************************************************************************************************************************
  128. ;******************************************************************************************************************************************
  129.  
  130. ^o::
  131.  
  132. Haystack =
  133. (
  134. Hello tom12@run.com more text,
  135. worked and joe.glines@gmail.com,
  136. did too and JoeShmoe@ai.com,
  137. this alsi works joes@school.edu,
  138. 432 444 Joe@marketing.cn 789456
  139. this is one more example Joe@the_automaror.com was here
  140. a|a|a|a
  141. )
  142. /*; this part read every line
  143. words := StrSplit(Haystack, "|") ; suveikia kaip explode
  144. for k,v in words
  145.     MsgBox % v  ; atvaizduoja po viena reiksme
  146. */
  147.  
  148. /*; this part read every line
  149. words := StrSplit(Haystack,[" ", "`n", "|"]) ; suveikia kaip explode tik su daugiau variantu
  150. for k,v in words
  151.     Msgbox % v ; atvaizduoja po viena reiksme
  152. */
  153. words := StrSplit(Haystack,[" ", "`n", "|"]) ; suveikia kaip explode tik su daugiau variantu
  154. for k,v in words
  155.     if(InStr(v,"@"))
  156.         emails.= v "`n" ; append value and new line to emails // sita vieta ir tokiu uzrasymu galima storinti issaugoti reiksmes is for kur gaunam
  157.     ;~ Msgbox % emails
  158.     FileAppend % emails, C:\Users\Rimas\Desktop\ahk_stuff\test1.txt
  159. return
  160.    
  161. Pos :=1 ;set starting point
  162. loop, {
  163.         Found_Pos := RegExMatch(Haystack, "(?:[\w_\.-]+)@(?:[\w\.-]+)\.(?:[a-z\.]{2,6})", Obj, Pos) ;
  164.         Pos := Found_Pos + StrLen(Obj) + 1
  165.         if not Obj ;if not found stop looping
  166.             break
  167.         emails .=Obj " `r" ;add to emails variable
  168. }
  169.  
  170. MsgBox % emails
  171.  
  172. return
  173.  
  174. ;******************************************************************************************************************************************
  175. ;******************************************************************************************************************************************
  176. ;******************************************************************************************************************************************
  177.  
  178.  
  179. ;                 LOOP THOUGH OUTLOOK FOLDERS
  180. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  181. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  182. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  183. ;time 39:45
  184.  
  185. /*
  186. ; mail := ComObjActive("Outlook.Application").GetNameSpace("MAPI").GetDefaultFolder[6] ; Inbox
  187. mail := ComObjActive("Outlook.Application").GetNameSpace("MAPI").GetDefaultFolder[6].Folders("AutoHotKey")
  188.  
  189. MsgBox, % "There are " mail.Items.Count " emails in the  " mail.Name " folder"
  190. Loop % mail.Items.Count
  191. {
  192.     ;~ if instr(mail.Items[A_Index].SenderName,"Joe Glines") {
  193.     if instr(mail.Items[A_Index].Subject,"Autohotkey") {
  194.         Item := mail.Items(A_Index) ; Sets Item to the values of the selected email
  195.        
  196.         MsgBox, % "To: `t" Item.To "`nSubject:`t" Item.Subject ; . "`nBody:`t" Item.Body
  197.         ; mail.Items[A_Index].Display() ;show emails
  198.     }
  199. }
  200.  
  201. return
  202. */
  203.  
  204. ;                 KAZKOKS KITAS APPROACHAS
  205. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  206. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  207. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  208. ;https://www.autohotkey.com/boards/viewtopic.php?t=67224
  209. /*
  210. oOutlook := ComObjActive("Outlook.Application") ; MsgBox, % COMObjActive("Outlook.Application").ActiveExplorer.Selection.Item(1).SenderName ; neaisku kurioje vietoje sitas turi buti, galv ietoje 209 eilutes
  211. oInspector := oOutlook.Application.ActiveInspector
  212. MsgBox, % COMObjActive("Outlook.Application").ActiveExplorer.Selection.Item(1).SenderName ; neaisku kurioje vietoje sitas turi buti
  213. Mail := oInspector.CurrentItem ; getting current email object
  214.  
  215. ; Email-properties-list
  216. ; https msdn.microsoft.com /en-us/library/office/ff868262.aspx  Broken Link for safety
  217. m_subject:=mail.subject
  218. m_senderemailaddress:=mail.senderemailaddress ; "[email protected]"
  219. m_sendername:=RegExReplace(mail.sendername,"[^\w ]")
  220. m_ReceivedTime:=mail.ReceivedTime  ; "03.04.2015 15:38:56"
  221.  
  222. return
  223. */
  224.  
  225.  
  226.  
  227.  
  228. ;                 MOVE FOLDERS TO ANOTHER FOLDER
  229. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  230. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  231. ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  232. ;You need to adjust the folder and/or subfolders structure which will be similar to a path.
  233. ;Hi guys, i am trying to move selected emails to a folder without success
  234. ; https://www.autohotkey.com/boards/viewtopic.php?t=63301
  235. /*
  236. F12::
  237.     olApp := ComObjCreate("Outlook.Application")
  238.     olNameSpace := olApp.GetNamespace("MAPI")
  239.     olDestFolder := olNameSpace.Folders("[email protected]").Folders("Deleted Items")
  240.    
  241.     olEmails := olApp.ActiveExplorer.Selection
  242.         For olEmail in olEmails
  243.         olEmail.Move(olDestFolder)
  244. return
  245. */
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253. ; --------------------------------------------------------------------------------------------------------------------------------------------------------
  254. ; ######################### Find folder in outlook - need to check #########################
  255. ; --------------------------------------------------------------------------------------------------------------------------------------------------------
  256.  
  257. ^!j::
  258. Mail := ComObjActive("Outlook.Application").GetNameSpace("MAPI").GetDefaultFolder[6].Folders("Automate")
  259. Loop % mail.items.Count {
  260. MsgBox % mail.items[a_index].SenderName a_tab mail.items[a_index].subject
  261. }
  262.  
  263. return
  264.  
  265.  
  266.  
  267. ; --------------------------------------------------------------------------------------------------------------------------------------------------------
  268. ; ######################### Find recieved time from outlook email #########################
  269. ; --------------------------------------------------------------------------------------------------------------------------------------------------------
  270. ;example from fornum: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=80825&p=351742#p351742
  271. ; regex \d{8}\s[a-zA-Z]+\s\d|\d{8} find fornyelsecode or just number
  272. F5::
  273.     olApp := ComObjCreate("Outlook.Application")
  274.     olNameSpace := olApp.GetNamespace("MAPI")
  275.     olFolder := olNameSpace.Folders("[email protected]").Folders("Inbox")
  276.     sSubject := "VM8743"
  277.     for olItem in olFolder.Items.Restrict("@SQL=""http://schemas.microsoft.com/mapi/proptag/0x0037001f"" = '" sSubject "'")
  278.         MsgBox % olItem.CreationTime "`n" olItem.ReceivedTime "`n" olItem.Subject "`n" olItem.Body  ; Any valid Item property will work here
  279. return
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293. !r::Reload
  294. !z::Pause
  295. !x::ExitApp
  296.  
  297.  
  298.  
  299.  
  300.  
Add Comment
Please, Sign In to add comment