Send outlook email with hyperlink

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Send outlook email with hyperlink

Post by JustinNL » 14 Jul 2021, 14:40

Hi guys,

I have a question concerning Outlook.
I have a script that creates a new email in outlook with a standardized text.
This text contains some hyperlinks and I want to send this text as a clickable hyperlink, rather than as plain text.

This is my code so far:

Code: Select all

^#y::
Outlook := ComObjActive("Outlook.Application")
email := Outlook.Application.CreateItem(0)
email.To := emailadres 
email.Sender := test@test.nl
email.Subject := "email subject"

myInspector :=	email.GetInspector, myInspector.Activate
Run,OutlookError.ahk ; an error is generated concerning safety issues in outlook is clicked away with this ahk file

wdDoc :=	myInspector.WordEditor
wdRange :=	wdDoc.Range(0, wdDoc.Characters.Count)
wdRange.InsertBefore(email "body text of the email, http`://www.google.nl")
return
Until then it works fine but sends the link as plain text
I can move the caret to the link and press space and a hyperlink is created.

Looking online it looks as if I can add a link using html <a href="www.google.nl"> LINK TEXT </a>, however when I add this to the script is doesn't work.

Code: Select all

wdRange.InsertBefore(email "body text of the email" & "<a href=""www.google.nl"">link</a>")
I am using InsertBefore so that the standard signature in Outlook is maintained.

Do you have any suggestions how I can create an email with clickable hyperlinks that also maintains the standard Outlook signature?

Thanks in advance for your help,
Best,
Justin
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Send outlook email with hyperlink

Post by FanaticGuru » 14 Jul 2021, 15:48

JustinNL wrote:
14 Jul 2021, 14:40
Hi guys,

I have a question concerning Outlook.
I have a script that creates a new email in outlook with a standardized text.
This text contains some hyperlinks and I want to send this text as a clickable hyperlink, rather than as plain text.

This is my code so far:

Code: Select all

^#y::
Outlook := ComObjActive("Outlook.Application")
email := Outlook.Application.CreateItem(0)
email.To := emailadres 
email.Sender := test@test.nl
email.Subject := "email subject"

myInspector :=	email.GetInspector, myInspector.Activate
Run,OutlookError.ahk ; an error is generated concerning safety issues in outlook is clicked away with this ahk file

wdDoc :=	myInspector.WordEditor
wdRange :=	wdDoc.Range(0, wdDoc.Characters.Count)
wdRange.InsertBefore(email "body text of the email, http`://www.google.nl")
return
Until then it works fine but sends the link as plain text
I can move the caret to the link and press space and a hyperlink is created.

Looking online it looks as if I can add a link using html <a href="www.google.nl"> LINK TEXT </a>, however when I add this to the script is doesn't work.

Code: Select all

wdRange.InsertBefore(email "body text of the email" & "<a href=""www.google.nl"">link</a>")
I am using InsertBefore so that the standard signature in Outlook is maintained.

Do you have any suggestions how I can create an email with clickable hyperlinks that also maintains the standard Outlook signature?

Thanks in advance for your help,
Best,
Justin

If you are just going the wdDoc route to maintain the signature, you can maintain the signature like this:

Code: Select all

olApp := ComObjActive("Outlook.Application")
olItem := olApp.ActiveWindow.CurrentItem
olItem.HTMLBody := "Stuff Before Current Body" olItem.HTMLBody "Stuff After Current Body"
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
JustinNL
Posts: 28
Joined: 01 Sep 2020, 13:22

Re: Send outlook email with hyperlink

Post by JustinNL » 15 Jul 2021, 06:04

Thanks that was exactly what I needed. I've set the email up in HTML and the links work fine!

I have one additional question, when you run the script you get a message like "an external program is trying to access outlook". I have made a script (OutlookError.ahk) that just controlclick's the 'accept' button.
However, is there any way to automatically prevent this warning message?

Best,
Justin
miracle
Posts: 14
Joined: 24 Jan 2020, 12:22

Re: Send outlook email with hyperlink

Post by miracle » 15 Jul 2021, 07:09

you need an antivirus or windows defender to disable the message
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Send outlook email with hyperlink

Post by FanaticGuru » 15 Jul 2021, 17:27

JustinNL wrote:
15 Jul 2021, 06:04
Thanks that was exactly what I needed. I've set the email up in HTML and the links work fine!

I have one additional question, when you run the script you get a message like "an external program is trying to access outlook". I have made a script (OutlookError.ahk) that just controlclick's the 'accept' button.
However, is there any way to automatically prevent this warning message?

Best,
Justin
To expand on @miracle, Outlook has an option under Trust Center > Programmatic Access. You can set it to only warn about suspicious activity like this when your Antivirus software is out-of-date or not present. Outlook talks with Antivirus software and will not warn if Outlook finds the Antivirus software adequate.

So you need to set the option correctly in Outlook and then have suitable Antivirus running. There is probably a way to tell Outlook to trust a specific program but I have never gone that route.

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
Post Reply

Return to “Ask for Help (v1)”