Link to home
Start Free TrialLog in
Avatar of acampoma
acampoma

asked on

Create An Outlook Alert - Non Received E-Mails

How do I create an alert for E-Mails that I do not receive by a certain time.

I am administering a report delivery system (Microstrategy Narrowcast Server); Error notification is poor - The only way I know 100% whether a report was delivered or not is by checking for non-received E-Mails
I send out hundreds of reports per week and I get BCC'ed on them all; I then go down a checklist manually to determine if a report was sent or not sent
How can I set up an alert to advise me when a report is not delivered by a specific time?
I can place a string or a GUID in the body to subject line to denote uniqueness; How do I scan for somthing like this?
Is this at all possible?

Avatar of David Lee
David Lee
Flag of United States of America image

Greetings, acampoma.

I think I can do this with an Outlook macro.  Here are the steps I think this'd require.

1.  Outlook starts and creates a task, with reminder, to watch for the email.
2.  If the subject email does not arrive by the teim the task deadline hits, then the task reminder will pop up.
3.  If the subject email does arrive, then it resets the task's due date/time to when the next message should arrive.

If that logic sounds right, and if using a macro is acceptable, then I can put the coded together and get it posted.

Cheers!
Avatar of acampoma
acampoma

ASKER

Sorry for the late reply - Yes; a macro would be fine
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Had to do a bit of adjusting. works great; Thanks
Great!  Glad I could help out.
Can this code be modifed so that instead of showing an alert Outlook can send an email or sms to a specific address instead?
Hi, fireaxe.

Yes the code can be modified to send an email or an SMS.  I'll be glad to help with that if you want to open a question.
I really need this to work but when I try it, it says ''sub or function not defined'' at line 26.

Any Idea?

Can you give me an example with task name and subject in the code?

Thanks in advance
Hi, christianduf.

To avoid the possibility that line 26 on my end isn't the same as line 26 on your end, which line are we talking about?  
Thanks for the reply, here's my code:

'Macro Begins Here
Public WithEvents olkInbox As Outlook.Items

Private Sub Application_Quit()
    Set olkInbox = Nothing
End Sub

Private Sub Application_Startup()
    Set olkInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub olkInbox_ItemAdd(ByVal Item As Object)
    If Item.Class = olMail Then
        'Change Watcher Update to the subject text you want to key on
        If Item.Subject = "Email Subject" Then
            'Change 1 to the number of hours you want to wait for the next message to arrive
            ManageWatcherTask Now + 1
            Item.UnRead = False
            Item.Save
        End If
    End If
End Sub

Sub ManageWatcherTask(datDateDue As Date)
    Dim olkTaskFolder As Outlook.Items, _
        olkTask As Outlook.TaskItem
    Set olkTaskFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks).Items
    'Change Watcher Task to whatever task name you want to use
    Set olkTask = olkTaskFolder.Find("[Subject] = 'Outlook Task'")
    If Not IsNothing(olkTask) Then
        olkTask.ReminderTime = datDateDue
        olkTask.ReminderSet = True
    Else
        Set olkTask = Application.CreateItem(olTaskItem)
        With olkTask
            .DueDate = datDateDue
            'Chagne Watcher Task to match the task name used above
            .Subject = "Outlook Task"
            .ReminderTime = datDateDue
            .ReminderSet = True
        End With
    End If
    olkTask.Save
    Set olkTask = Nothing
End Sub
'Macro Ends Here

1. I create a task in Outlook called: Outlook Task

2. If I send an email with 'Email Subject' as the Subject, outlook gives me an error: Sub or function not defined and this line is yellow: Sub ManageWatcherTask(datDateDue As Date)

If I send an email with something else as the subject, nothing happens which is good.

Thanks again
When the error occurs and you are taken to the debugger what line of code does it go to?  I know it highlights the line you mentioned, but that's telling us there's an error in that procedure.  It doesn't mean there's a problem with that line.  I need to the line the error is on.
Hi Blue,

It highlights the word  ''IsNothing'' in the line If Not IsNothing(olkTask) Then.

Thanks again, very appreciated.

 
Ahhh.  Looks like a function is missing from the original code.  Here's that function.  Add it to the code you already have.
Function IsNothing(objItem As Object)
    ' Purpose: Tests to see if an object is not set to any value.'
    ' Written: 4/24/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: All versions'
    IsNothing = (TypeName(objItem) = "Nothing")
End Function

Open in new window

It look like a task error,

You wrote:

14.  Create a task with the same subject text that appears in the subroutine called olkInbox_ItemAdd.

My subject is ''Email Subject''

My task name needs to be Email Subject? Or the name I put  instead of ''Watcher Task''

Right.  The name that appears on this line of code in olkInbox_ItemAdd

    If Item.Subject = "Email Subject" Then

has to be the same name used on these two lines of code in ManageWatcherTask

    Set olkTask = olkTaskFolder.Find("[Subject] = 'Outlook Task'")
    .Subject = "Outlook Task"

That name can be anything you want it to be, it just has to be the same name in all three places.
If I put Email Subject everywhere, then the task subject (name) is Email subject, with a reminder of the time I need.

It still gives me the same error.

Can you put the an example with the code changed with ''Email Subject'' as the Key word for everything, and what the name of the Outlook task needs to be.

We're almost there, thanks.

Ok, I'm getting confused.  The name of the task cannot possible cause the error "sub or function not defined".  Only a missing sub or function can cause that.  If that's the error you're getting, then the task name isn't the issue.  If you're getting a different error, then I need to know what the error is and the line it's occurring on.
Damn I did not see your previous answer with the missing code

Function IsNothing(objItem As Object)
    ' Purpose: Tests to see if an object is not set to any value.'
    ' Written: 4/24/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: All versions'
    IsNothing = (TypeName(objItem) = "Nothing")
End Function

Where do I paste that, It must be it...

Thanks!

Put it with the rest of the code.  It doesn't matter what order the functions/subroutines appear in.
Thanks Blue,

It's working, you saved me a LOT of hassle and time.

Thanks again for your time,

You're welcome!  Glad I could help.
Hi Blue,

Is there a line I could put that would only look for a certain word in the Subject and not the exact word.

For example, my system sends me ''Engine on at 9h00'' as the subject. Can the code search for ''Engine on'' only.

Thanks again!
If it's easier, maybe a search by sender. It's always the same sender.

Thanks!
Sure.  In the subroutine olkInbox_ItemAdd change

        If Item.Subject = "Email Subject" Then

to

        If InStr(1,Item.Subject,"Engine on") Then

This will search for any occurrence of "Engine on" in the subject line.  The search is case sensitive.
Hi Blue,

Thanks again, I can't believe you're helping me so fast, I'm so glad!

You saved me a lot of problems! At least 3 hours of sleep for 300 days a year.

Thanks again,

Christian
You're welcome, Christian!  If there's anything else I can do, then you know where to find me.
Hi David,

What would need to be done to have Outlook send an email to specific email addresses?
Hi, Kevin.

Under what condition?
Similar to the original question.

I receive one email every morning around the same time, but sometimes the server fails.

If I don't receive it before a certain time (7am), I would like outlook to send an email to a few people saying "The report is delayed"

Thanks
Hi David,

Using your code, works great.

Have tried to change it to accept a passed variable as the taskname, but it cannot get the find function to select the existing task.

code is

Sub ManageWatcherTask(MailFrom, datDateDue As Date)
     Dim olkTaskFolder As Outlook.Items, _
         olkTask As Outlook.TaskItem
     Set olkTaskFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks).Items
     'Change Watcher Task to whatever task name you want to use
     MsgBox MailFrom
     Set olkTask = olkTaskFolder.Find("[Subject] = MailFrom")

even if the task exists this does not find it. Need to do this to detect different emails with different tasks.

Robert
Hi, Robert.

All you need to do is change this line

Set olkTask = olkTaskFolder.Find("[Subject] = MailFrom")

Open in new window


to

Set olkTask = olkTaskFolder.Find("[Subject] = '" & MailFrom & "'")

Open in new window

As Promised here is the modified code that can do Multi Alerts

'Macro Begins Here
 Public WithEvents olkInbox As Outlook.Items

 Private Sub Application_Quit()
     Set olkInbox = Nothing
 End Sub

 Private Sub Application_Startup()
     Set olkInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
 End Sub

 Private Sub olkInbox_ItemAdd(ByVal Item As Object)
     If Item.Class = olMail Then
         'Change Text to the subject text you want to key on
         If InStr(1, Item.Subject, "Subject 1") Then
             'Change 1 to the number of DAYS you want to wait for the next message to arrive
             TaskName = Item.SenderEmailAddress + "-" + Item.Subject
             ManageWatcherTask TaskName, Now + 1.01 'One day 15 Min
             Item.UnRead = False
             Item.Save
         ElseIf InStr(1, Item.Subject, "Subject 2") Then
             TaskName = Item.SenderEmailAddress + "-" + Item.Subject
             ManageWatcherTask TaskName, Now + 0.27 '6 1/2 Hours
             Item.UnRead = False
             Item.Save
         ElseIf InStr(1, Item.Subject, "Subject 3") Then
             TaskName = Item.SenderEmailAddress + "-" + Item.Subject
             ManageWatcherTask TaskName, Now + 1.04 '1 day 1 hour
             Item.UnRead = False
             Item.Save
         End If
         
     End If
 End Sub

 Sub ManageWatcherTask(MailFrom, datDateDue As Date)
     Dim olkTaskFolder As Outlook.Items, _
         olkTask As Outlook.TaskItem
     Set olkTaskFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks).Items
     Set olkTask = olkTaskFolder.Find("[Subject] = '" & MailFrom & "'")
     If Not olkTask Is Nothing Then
         With olkTask
             .DueDate = datDateDue
             .ReminderTime = datDateDue
             .ReminderSet = True
         End With
     Else
         Set olkTask = Application.CreateItem(olTaskItem)
         With olkTask
             .DueDate = datDateDue
             .Subject = MailFrom
             .ReminderTime = datDateDue
             .ReminderSet = True
         End With
     End If
     olkTask.Save
     Set olkTask = Nothing
 End Sub
 'Macro Ends Here

If more then 3 subjects are required duplicate the Elseif Sections

Each email address that the email is received from with the subject creates a seperate task so that each can be tracked.