AHK ControlGetText Body Mail Outlook

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
anwikipedia
Posts: 22
Joined: 19 Sep 2023, 22:28

AHK ControlGetText Body Mail Outlook

Post by anwikipedia » 20 Sep 2023, 02:16

This is my code to get time,subject mail, body mail outlook.
Everything work except body mail. It only show "Message" when use MsgBox. I don't know what wrong with this code. Thanks for help.

Code: Select all

ControlGetText, VarFullTime, RichEdit20WPT5, ahk_class rctrl_renwnd32
Sleep, 500
ControlGetText, VarSubject, RichEdit20WPT7, ahk_class rctrl_renwnd32
Sleep, 500
ControlGetText, VarBody, _WwG1, ahk_class rctrl_renwnd32
Sleep, 500
MsgBox, 0, , 
(LTrim
%VarFullTime%
%VarSubject%
%VarBody%
), 500
[Mod edit: Since this is AHK v1 code, topic moved from v2 help..]
Ahk_fan
Posts: 238
Joined: 31 Aug 2018, 14:34
Contact:

Re: AHK ControlGetText Body Mail Outlook

Post by Ahk_fan » 22 Sep 2023, 06:43

alternative: this function connects to Outlook and reads actually selected Mail.

call

Code: Select all

EmailOutlookInformation(Sub, Body, SenderEmail, SenderNames)
msgbox, %Sub%, %Body%, %SendeEmail%, %SenderNames%
and this Function:

Code: Select all

EmailOutlookInformation(Byref Subject, Byref Body, Byref SenderEmail, byref SenderName) {

		Ol := ComObjActive("Outlook.Application")
		Selection := Ol.ActiveExplorer().Selection
		Loop, % Selection.Count
		{
			ThisItem := Selection.Item(A_Index)
			DateReceivedTime := RegExReplace(ThisItem.ReceivedTime, "\W")

			DateMailDD := SubStr(DateReceivedTime, 1, 2)
			DateMailMM := SubStr(DateReceivedTime, 3, 2)
			DateMailYYYY := SubStr(DateReceivedTime, 5, 4)
			DateMail := DateMailYYYY . DateMailMM . DateMailDD
			
			TimeMail := SubStr(DateReceivedTime , 9, 6)
			
			DateReceivedTime := DateMail . "" . TimeMail
			Subject := ThisItem.Subject
			SenderName := ThisItem.SenderName
			
			SenderEmail := ThisItem.SenderEmailAddress
			SenderEmailType := ThisItem.SenderEmailType
			Body := ThisItem.Body
			RecipientsCount := ThisItem.Recipients.Count
			loop, %RecipientsCount%
			{
				SendTo2 := SendTo2 "/" ThisItem.Recipients(A_Index).Name
			}
		}
}
regards,
AHK_fan :)
https://hr-anwendungen.de
anwikipedia
Posts: 22
Joined: 19 Sep 2023, 22:28

Re: AHK ControlGetText Body Mail Outlook

Post by anwikipedia » 22 Sep 2023, 11:38

Ahk_fan wrote:
22 Sep 2023, 06:43
alternative: this function connects to Outlook and reads actually selected Mail.

call

Code: Select all

EmailOutlookInformation(Sub, Body, SenderEmail, SenderNames)
msgbox, %Sub%, %Body%, %SendeEmail%, %SenderNames%
and this Function:

Code: Select all

EmailOutlookInformation(Byref Subject, Byref Body, Byref SenderEmail, byref SenderName) {

		Ol := ComObjActive("Outlook.Application")
		Selection := Ol.ActiveExplorer().Selection
		Loop, % Selection.Count
		{
			ThisItem := Selection.Item(A_Index)
			DateReceivedTime := RegExReplace(ThisItem.ReceivedTime, "\W")

			DateMailDD := SubStr(DateReceivedTime, 1, 2)
			DateMailMM := SubStr(DateReceivedTime, 3, 2)
			DateMailYYYY := SubStr(DateReceivedTime, 5, 4)
			DateMail := DateMailYYYY . DateMailMM . DateMailDD
			
			TimeMail := SubStr(DateReceivedTime , 9, 6)
			
			DateReceivedTime := DateMail . "" . TimeMail
			Subject := ThisItem.Subject
			SenderName := ThisItem.SenderName
			
			SenderEmail := ThisItem.SenderEmailAddress
			SenderEmailType := ThisItem.SenderEmailType
			Body := ThisItem.Body
			RecipientsCount := ThisItem.Recipients.Count
			loop, %RecipientsCount%
			{
				SendTo2 := SendTo2 "/" ThisItem.Recipients(A_Index).Name
			}
		}
}
This is so amazing. How u can write it so perfectly.
How you can ignore <link> from that text. I mean plain text.
This is my sample data
<https://> <https://>

<https://>

text <https://> : text1 text2 <https://>

text4
How to extract it to plain text with out link like below.

text: text1 text2
text4
idk how to say thank you better.

Update : never mind sir . I found it . it name SendRaw, %Body%.
Omg thank you sir. If you read this please let me know where to learn to write that function .

Update : SendRaw not working it still have many text like : <link> text <link>.
Now i have to find a way to remove all this <link> :(
Ahk_fan
Posts: 238
Joined: 31 Aug 2018, 14:34
Contact:

Re: AHK ControlGetText Body Mail Outlook

Post by Ahk_fan » 25 Sep 2023, 09:58

i think your Problem is that your Email is HTML formatted.So its not possible to get plain text,except you use

Code: Select all

StrReplace
or something similar.

Code: Select all

newBody := StrReplace(Body, "<https://>","")
msgbox, %newBody%
regards,
AHK_fan :)
https://hr-anwendungen.de
anwikipedia
Posts: 22
Joined: 19 Sep 2023, 22:28

Re: AHK ControlGetText Body Mail Outlook

Post by anwikipedia » 26 Sep 2023, 02:43

Ahk_fan wrote:
25 Sep 2023, 09:58
i think your Problem is that your Email is HTML formatted.So its not possible to get plain text,except you use

Code: Select all

StrReplace
or something similar.

Code: Select all

newBody := StrReplace(Body, "<https://>","")
msgbox, %newBody%
Yes bro.
How about express regrex anything start with < and end with > .
I mean <*>
This is my edit from your code

Code: Select all

newBody := StrReplace(Body, "<*>","")
msgbox, %newBody%
Post Reply

Return to “Ask for Help (v1)”