Automatically open link in email received

Status
Not open for further replies.

traph

New Member
Outlook version
Email Account
POP3
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
 
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.
 
Thanks so much Diane, I will test this and let you know. Hope it's simple enough for me too try it out.

Traph
 
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
 
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.
 
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
 
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...
 
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...
 
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.
 
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.
 
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. :(
 
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:
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.
 
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:
 
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
 
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
 
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
 
Hi all
i have problem like traph
can you help me to solve this
i need to click automatically in hyperlink in email
Regards
 
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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A How to open a specific link automatically with outlook 2016 Outlook VBA and Custom Forms 6
A How to open a specific link automatically with outlook Outlook VBA and Custom Forms 13
W Automatically open attachments without automatically printing them Using Outlook 0
kburrows Outlook Automatically Merging Contacts Using Outlook 1
A Opening a link from an email automatically Outlook VBA and Custom Forms 0
A Opening a link from a specific sender automatically Outlook VBA and Custom Forms 4
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
J Calendar events created on iPhone automatically changing default alert from 'None' to 'Time of Event' Using Outlook.com accounts in Outlook 0
Z Automatically adjust Outlook Reading Pane from bottom to right depending on portrait or landscape window Using Outlook 1
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
Hornblower409 Automatically or Manually Backup Multiple Versions of VbaProject.OTM Outlook VBA and Custom Forms 1
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
G automatically choosing "add to autocorrect" option Using Outlook 0
L Why are some email automatically going to "archive" Using Outlook 2
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
G Automatically delete messages in the synchronization folder Outlook VBA and Custom Forms 3
C Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 4
E Remove flag automatically Using Outlook 4
T Outlook 365 Move newly created tasks automatically on save. Outlook VBA and Custom Forms 1
M Outlook 365 Switching from AOL to Yahoo automatically Using Outlook 5
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
B Zoom automatically next email item (VBA) Outlook VBA and Custom Forms 2
Paul Hobbs Automatically accept "Empty Folders" prompt Outlook VBA and Custom Forms 6
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
M Automatically add senders first name to a greeting Outlook VBA and Custom Forms 1
C Add Form to Appointments Received, Automatically Outlook VBA and Custom Forms 6
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
Y Outlook 2013 Stop Outlook from automatically assigning categories to Tasks Using Outlook 0
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
P Automatically Categorize Meetings once they are accepted Outlook VBA and Custom Forms 5
N How to set automatically the default or user defined Quickstyle Templates by Answer in Outlook Using Outlook 1
O Run macro automatically at sending an email Using Outlook 11
D Outlook 2016 automatically increment anniversaries Using Outlook 1
T Office 2013 no longer updating automatically Using Outlook 2
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
N how to sync automatically when outlook opens Using Outlook 10
A Sort emails into subfolders based on sender and deleting emails automatically Outlook VBA and Custom Forms 3
undercover_smother Automatically Forward All Sent Mail and Delete After Send Outlook VBA and Custom Forms 10
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
R Make Enter Network Password Prompt Go Away Automatically Using Outlook 0
I Print Automatically Attachments Outlook VBA and Custom Forms 3
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7
M Outlook 2016 Rules Not Working Automatically Using Outlook 5
Diane Poremsky Automatically create a task when sending a message Using Outlook 0
D Is it possible to automatically send an email when it is moved to a folder? Exchange Server Administration 1
A Automatically send email based on drop-down field? Outlook VBA and Custom Forms 2

Similar threads

Back
Top