Outlook 2013 - How give text of mail object ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

Outlook 2013 - How give text of mail object ?

24 May 2017, 05:44

Hi all,

i need to give the text of selected mail object for:

search for a 14 char string witch begin with IT001E followed by "nnnnnnnn"
start one macro to search the 14 char string into other web application (and this it not a problem)

so, one step at time, how to have complete mail object string from the preview box of Outlook ?

... with COM if it possible ;)
User avatar
FanaticGuru
Posts: 1905
Joined: 30 Sep 2013, 22:25

Re: Outlook 2013 - How give text of mail object ?

24 May 2017, 13:24

Not real sure what you are looking for but here is a start.

This will loop through the selected emails in Outlook and display the subject of each of those emails.

Code: Select all

F12::
    Emails := ComObjActive("Outlook.Application").ActiveExplorer.Selection
    For Email in Emails
		MsgBox % Email.Subject
return
You could do lot of different things with those selected emails.

Here is the MSDN of a MailItem
https://msdn.microsoft.com/en-us/librar ... 61332.aspx

After Email in the code you can change Subject to any of the Methods or Properties listed. Methods cause an action to occur like Delete. Properties gets or sets information like Subject.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

Re: Outlook 2013 - How give text of mail object ?

23 Jun 2017, 05:30

Now ... all work ok but I want to simply "replay" to this mail.

Code: Select all

    Emails := ComObjActive("Outlook.Application").ActiveExplorer.Selection
    For Email in Emails
	OggettoMail := Email.Subject
Then my routine search object for "IT001Ennnnnn" and open new mail ...

Like write before I need now to simply "open" replay box from selected mail item ... help :angel:
User avatar
FanaticGuru
Posts: 1905
Joined: 30 Sep 2013, 22:25

Re: Outlook 2013 - How give text of mail object ?

23 Jun 2017, 12:26

Below code will reply to the first email in selection.

Code: Select all

Emails := ComObjActive("Outlook.Application").ActiveExplorer.Selection	; get all emails selected
Email_Reply := Emails.Item(1).Reply	; create reply to the first email
Email_Reply.Display	; display the reply
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

Re: Outlook 2013 - How give text of mail object ?

26 Jun 2017, 03:05

Thanks, it's simply but I have problem to find solution :oops:

after, if want write something into reply:

Code: Select all

myInspector :=	Email_Reply.GetInspector, myInspector.Activate
wdDoc :=	myInspector.WordEditor
wdRange :=	wdDoc.Range(0, wdDoc.Characters.Count)
wdRange.InsertBefore("... body text HERE ...") ; or put text into variable: wdRange.InsertBefore(variable)
;)
Last edited by scriptors on 26 Jun 2017, 04:34, edited 1 time in total.
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

Re: Outlook 2013 - How give text of mail object ?

26 Jun 2017, 04:33

and, if you want to Reply all persons into email:

Emails := ComObjActive("Outlook.Application").ActiveExplorer.Selection ; get all emails selected
Email_Reply := Emails.Item(1).ReplyAll ; create reply to the first email with ALL adress
Email_Reply.Display ; display the reply
User avatar
FanaticGuru
Posts: 1905
Joined: 30 Sep 2013, 22:25

Re: Outlook 2013 - How give text of mail object ?

26 Jun 2017, 13:19

scriptors wrote:Thanks, it's simply but I have problem to find solution :oops:

after, if want write something into reply:

Code: Select all

myInspector :=	Email_Reply.GetInspector, myInspector.Activate
wdDoc :=	myInspector.WordEditor
wdRange :=	wdDoc.Range(0, wdDoc.Characters.Count)
wdRange.InsertBefore("... body text HERE ...") ; or put text into variable: wdRange.InsertBefore(variable)
;)
To set the "body" of an email is very simple:

Code: Select all

Email_Reply.Body := "This is a test."	; Make the body of the email this
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
FanaticGuru
Posts: 1905
Joined: 30 Sep 2013, 22:25

Re: Outlook 2013 - How give text of mail object ?

26 Jun 2017, 13:24

If you want a fancier, HTML email, instead of just plain text you can do this:

Code: Select all

Picture := A_Desktop "\Temp\1024x1024.jpg"
html=
(
<html>
<body>
<font size="2" face="Calibri" color="black">
<p>Best Regards,<br>Have a nice day!<br>More Greetings and e-mails and that sort of stuff<br><br>
<b><font size="2">
Your Name</b><br>
<a href="mailto:[email protected]">[email protected]</a><br>
<img src=%Picture% alt="My picture";">
</body>
</html>
)
Email_Reply.HTMLBody := html
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

Re: Outlook 2013 - How give text of mail object ?

27 Jun 2017, 03:32

I search and make "script" posted below because have my personal signature on e-mail ...
now i'm not sure ... but if i set Email.Body have problem with signature

ps. i hope write correct english ;)
User avatar
FanaticGuru
Posts: 1905
Joined: 30 Sep 2013, 22:25

Re: Outlook 2013 - How give text of mail object ?

27 Jun 2017, 20:05

scriptors wrote:I search and make "script" posted below because have my personal signature on e-mail ...
now i'm not sure ... but if i set Email.Body have problem with signature

ps. i hope write correct english ;)
You might try this is you want to keep the existing body of an email and insert new stuff at beginning.

Code: Select all

Emails := ComObjActive("Outlook.Application").ActiveExplorer.Selection	; get all emails selected
Email_Reply := Emails.Item(1).ReplyAll	; create replyall to the first email
Email_Reply.Display	; display the reply
Email_Reply.HTMLBody := "This is a test." Email_Reply.HTMLBody	; Insert to beginning of  html body of email
If your Outlook is automatically starting with a signature this will keep that as well as the reply message below.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 185 guests