PDA

View Full Version : New Email from Specific Person



patrick07110
03-01-2009, 09:02 AM
Is there any way through vba to check new emails for a specific recipient and subject line? Once this happens have it delete the email and show a dialog box.

I'm trying to use outlook as a way to network all my people together. If I do it through a 'rule' the letter icon in the tray will not go away.

I'm basically trying to create a way that I can email a specific person and a dialog box telling them what to do next without interfering with their normal email tasks.

jfournier
03-02-2009, 09:20 AM
This is possible, using the Application_NewMail event in the ThisOutlookSession module in your Outlook VBA session. The NewMail event is triggered whenever an email arrives. Here's an example of how you could do what you want:

Private Sub Application_NewMail()
ProcessEmail Application.Session.GetDefaultFolder(olFolderInbox).items.GetLast()
End Sub

Private Sub ProcessEmail(TheMsg As MailItem)
If TheMsg Is Nothing Then Exit Sub
If Not TypeOf TheMsg Is MailItem Then Exit Sub
If TheMsg.SenderEmailAddress Like "xxx@yyy.com" And TheMsg.Subject Like "subject to trigger msgbox" Then
MsgBox "whatever you want to say"
End If
End Sub

However, using this would require that you paste into every persons Outlook VBA project where you want this installed. An alternative would be to develop a COM Addin that has the NewMail event hooked to the Outlook application, but it might be best to just start out at the VBA level...You could also consider using Visual Studio Tools for Office, which I believe would take care of a good amount of the overhead in setting up the addin...

Charlize
03-02-2009, 02:53 PM
What about using an external list that can be imported into an array. The list holds the e-mailaddress and the subject and the response.

Based on the first two conditions, a response mail is generated.

The reason for trying it like this, is that when you change the person or responses, you don't have to alter the coding but only the list.

Changing the list can be done manually, in notepad or excel or ..., or by creating a form in outlook or excel that you use to change the contents of this file.

Charlize