Automatically open link in email received

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#1
Hi All,

I am a freelancer agent and I am less than a novice when it comes to coding so I need some help please. I receive jobs via email which contains 2 links. 1 to accept the job and the 2nd is to decline it.

As I am on the road it is difficult getting reception and checking emails every few minutes so I need a script that runs on my PC as outlook 2007 is always open, that will automatically click on the "accept" link. I have tried running rules, by detecting key words in the incoming message, but the only option I have is to run a script and I am hopeless at that sort of thing. I am happy to pay for the script through PayPal, it's just that I have a very small window of opportunity to accept the job in.

Any help would be greatly appreciated, thanks.

Traph
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#2
Does the first macro at Open All Hyperlinks in an Outlook Email Message meet your needs? (You'll need to change .Global = True to .global = false to open just the first link.)

To test it as written, select a message and run the macro. Converting it to a script will be fairly simple if the macro works for you - I'll update that page with a run a script version that opens just the first link.
 

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#3
Thanks so much Diane, I will test this and let you know. Hope it's simple enough for me too try it out.

Traph
 

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#4
Hi Diane,

I inserted the script in VB editor, and added a rule to run the script. I get no errors however nothing happens when I send the test email to myself and upon receipt. not sure if I have missed anything, however I use Firefox as my default browser, would that cause it? I would have thought at the very least it would invoke IE and ask if I wanted it to be my default browser. I tried many different ways to get the script to work such as changing the line from IE to Firefox but to no avail, and no errors. I have also set the security to allow all just for testing.

Regards
Traph
 

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#5
have been testing different things all day and just discovered when I go to Tools>Macro>Macros although the code is in project1.thisoutlooksession.openlinks there are no macros to see. Not sure what I did or did not do. I followed the code copy/pasted it in thisoutlooksession it did not work, then added a module with the same code, also did not work. This is exactly what I am after but for some reason it won't work and does not give me any errors either.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#6
have been testing different things all day and just discovered when I go to Tools>Macro>Macros although the code is in project1.thisoutlooksession.openlinks there are no macros to see. Not sure what I did or did not do. I followed the code copy/pasted it in thisoutlooksession it did not work, then added a module with the same code, also did not work. This is exactly what I am after but for some reason it won't work and does not give me any errors either.
You did nothing wrong - because it is intended for run a script, it can only be called by something else (another macro or function), not run by itself. If you create a rule, you'll see it.

Anything with a title in this format: sub macroname(something here) is called by another macro or function - you'll won't see these in the macro list.

if you want to test it without running rules, use this macro - it passes the selected item to the links macro, just as a rule would.

Sub testmacro()
Dim Item As Outlook.MailItem
Set Item = Application.ActiveExplorer.selection.Item(1)
OpenLinksMessage Item
End Sub
 

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#7
Hi Diane,

I decided to start again, I have removed everything and here are the steps I have taken.

Opened the editor and inserted the code you mentioned as is (the one with global = false) in "thisoutlooksession" and saved it. I then went into the macros security and clicked "no security check for macros". I closed the editor and started a rule on incoming messages looking for the following in the body "you have a new job", and then chose "run a script" and chose "project1.thisoutlooksession.openlinks" and saved the rule. I closed outlook and restarted it, then used one of the messages that I had received and sent it to myself.

Upon receiving the message in my inbox nothing happens and no errors. I tried changing the line "internetexplorer.application" to "firefox.application" with no difference as well, so I am really not sure what I may have missed.

I also tried what you suggested with your last post and added the "testmacro" which inserted itself as "module1" under this "outlooksession" and every time I run the macro it reverts to the "outlooksession" window and gives this error "compile error: user-defined type not defined" and highlights the first line in blue "Public Sub OpenLinks(olMail As Outlook.MailolMail". I tried closing and restarting outlook as well with same results so I deleted "module1" and reverted to the script I initially had added.

Sorry...
 

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#8
I started looking around the web for a solution as to why the script will not work, and found the following script which works by starting the browser and I have tested it, the only problem is when I change this line from [If Left(splitWord,7)="http://"Then] to [If Left(splitWord,8)="https://"Then] it stops working. I tried leaving it as is before and it opens the correct page however it fails because it is opening the page unsecured as in http:// rather than https:// hence it fails. Here is the code that works, maybe the problem is that I am using outlook 2007???

Sub LaunchURL(itm As MailItem)

Dim bodyString AsString
Dim bodyStringSplitLine
Dim bodyStringSplitWord
Dim splitLine
Dim splitWord

bodyString = itm.Body
bodyStringSplitLine = Split(bodyString, vbCrLf)

ForEach splitLine In bodyStringSplitLine
bodyStringSplitWord = Split(splitLine," ")

ForEach splitWord In bodyStringSplitWord
If Left(splitWord,7)="http://"Then
Shell ("C:\Program Files\Internet Explorer\IEXPLORE.EXE"&" "& splitWord)
EndIf
Next

Next

Set itm =Nothing
EndSub

PrivateSub test()
Dim currItem As MailItem
Set currItem = ActiveInspector.currentItem
LaunchURL currItem
EndSub

The code above always works on an incoming message using a rule that looks for a keyword in the body of the message, however my issue now is working out the "https://" bit...
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#9
olMail As Outlook.MailolMail
oh shoot... when i worked on the macro to convert it to a script, my mouse slipped and i didn't notice i typed in the wrong place. i didn't realize i posted it to the site before realizing the error.

it should be olmail as outlook.mailitem

Sorry about that.
 

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#10
that's ok. I tried the new code and now I get a window pop up "compile error: user-defined type not defined" and the highlighted line is "Reg1 As RegExp" with the top line in yellow.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#11
You need to go to Tools, References and add a check to Microsoft VBScript Regular Expressions 5.5. I normally add that to the page when it's needed - not sure how it got forgotten for that page. :(
 

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#12
That's quite complex. I did I you requested and it invoked IE however returned this error on the page "bad url -" with a bunch of numbers that refer to the actual site. It seems it's not sending the whole url when opening the page. The link that needs to be followed look like this "https://portal.idsecure.com.au/job/accept/1234/1234" and the link that opens in the page looks like this "http://mandrillapp.com/track/click/30369745/portal.idsecure.com" at least it started IE.

Sorry about all this, this is way way beyond me.
 
Last edited by a moderator:

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#13
ok, I sorted out the issue of the link and I removed the following [>\.] so it now parses the whole url intact and that's great. a little snag is that IE will not display any page unless it starts with https://www.etc so when the parsed page starts with https://portal.etc it returns a DNS error and the page cannot be displayed. Could I run firefox instead? I tried changing InternetExplorer.Application to Firefox.Application as it is my default browser but firefox won't start for some reason.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#14
ok, I sorted out the issue of the link and I removed the following [>\.] so it now parses the whole url intact and that's great. a little snag is that IE will not display any page unless it starts with https://www.etc so when the parsed page starts with https://portal.etc it returns a DNS error and the page cannot be displayed. Could I run firefox instead? I tried changing InternetExplorer.Application to Firefox.Application as it is my default browser but firefox won't start for some reason.
So it's getting the correct url now? It gets the first url in the message, which in HTML messages might not be the first obvious url. Senders can bury them pretty good - but in your case, since you are looking for a specific url you could use a pattern something like ("https://portal.idsecure.com.au/job/accept/[0-9]*/[0-9]*/")

I think I'd try to figure out why it won't work in IE - it definitely show be able to display HTTPS urls. Firefox doesn't support COM objects, so you can't automate it - but you can use shell command lines to open it -

Set M1 = Reg1.Execute(olMail.Body)
For Each M In M1
strURL = M.SubMatches(0)
Debug.Print strURL
If InStr(strURL, "unsubscribe") Then GoTo NextURL

Shell """" & "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" & """" & " -new-tab " & strURL
NextURL:
 

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#15
Thanks Diane. I shall figure out why IE only opens sites starting with www the strange thing is it opens other secure sites that do not start with www, however the server changes and adds the www to the site address and the address bar. I really appreciate your help with this, don't know about you but it is a challenge for me. I will also try to see if I can ger firefox started as you suggested, might be easier long term.

Regards
Traph
 

traph

New Member
Outlook version
Outlook 2007
Email Account
POP3
#16
brilliant. It took me a while to figure out the shell command and having to remove the reference to IE, silly me. I told you I am less than novice when it comes to this sort of thing. I don't know how to thank you, you have been a blessing, thank you so much for taking the time and I am sorry if I caused any stress, God bless you I know I felt it.

Kindest Regards
Tony
 
Outlook version
Outlook 2013 64 bit
Email Account
Office 365 Exchange
#17
Diane, I know this thread is old. You still around? I have been reading your stuff for years and have solved many tasks doing so. The latest has me stumped, therefore I am now posting. I am a complete noob, but know my way around to get a few things accomplished. I need to do somewhat what Traph did above.

I need to automatically launch a specifically named anchored hyperlink (called LAUNCH) that is coming from a specific sender (test@testing.com). I have found some references to using "WordEditor" to inspect the hyperlink and launch it (h.follow), but I cannot figure out how to get it to only launch on a specific word from a specific sender.

I hope you are still around. You have been brilliant. Cheers.
Keogh
 

ahmad19

New Member
Outlook version
Outlook 2010 64 bit
Email Account
POP3
#18
Hi all
i have problem like traph
can you help me to solve this
i need to click automatically in hyperlink in email
Regards
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#19
I need to automatically launch a specifically named anchored hyperlink (called LAUNCH) that is coming from a specific sender (test@testing.com). I have found some references to using "WordEditor" to inspect the hyperlink and launch it (h.follow), but I cannot figure out how to get it to only launch on a specific word from a specific sender.
Sorry I missed this when you posted it. First, do a debug.print on a message you need to get the url form, so you can see how outlook formats it -
Debug.Print olMail.Body

The url should be in this format: keyword <https://url> so you'd need to find the pretty word then find the url in the html string.

For example to open the links to "View this thread" in forum notifications, I'd change the code block to the following:

Code:
With Reg1
 .Pattern = "View this thread <(.*)>"
 .Global = True
 .IgnoreCase = True
 End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)
 For Each M In M1
   strURL = M.SubMatches(0) 
    Debug.Print strURL

To get the body, as the macro sees it, run this on a message and look in the Immediate window.
Code:
Sub printbody()
Dim Item As Outlook.MailItem
Set Item = Application.ActiveExplorer.Selection.Item(1)
Debug.Print olMail.Body
End Sub
 
Top