Forwarding a message and auto-reply

M

Mike

Can someone point me in the right direction or supply a snippet of code?
Here's what I want to do:

A new email comes in to an Outlook 2002 client that gets its mail from a
POP3. VBA code runs to determine the address of the sender and if it's one
of a select number of addresses, it replies automatically to the message and
places an informational message at the beginning. It also adds another email
address as a BCC to this outgoing message.

I'm fluent in VBA, but not the OL2 object model. Any assistance is
appreciated. Remover NOSPAM from the email address if you wish to reply
privately.

Thanks!

Mike
 
B

Bill James

The code below when added to ThisOutlookSession will run
Inbox_Items_ItemAdd() whenever a new object is put into
the inbox (Either by getting new mail or by drag & drop).

Here is a template:

' Start of ThisOutlookSession Class module
Option Explicit

Public WithEvents InboxItems As Outlook.Items

Private Sub Application_Startup()
Set InboxItems = Outlook.Session.GetDefaultFolder
(olFolderInbox).Items
End Sub

Private Sub InboxItems_ItemAdd(ByVal theItem As Object)
Dim SMTP as MailItem

If (TypeName(theItem) = "MailItem") Then
' Here we know that the new object is a MailItem
' so we can safely begin referencing it properties
If (theItem.SentOnBehalfOfName = "Joe Smith") then
' Create new outgoing mail object
Set SMTP as Application.CreateItem(olMailItem)
SMTP.Subject = "mySubject"
SMTP.TO = "(e-mail address removed)"
SMTP.Body = "Standard Message"
SMTP.Body = SMTP.Body & vbCrLf & "some more"
SMTP.Send
'Debug.Print theItem.ReceivedByName
'Debug.Print theItem.SentOnBehalfOfName
'Debug.Print theItem.ReceivedOnBehalfOfName
'Debug.Print theItem.ReplyRecipientNames
' ... bunch of other properties ...
Set SMTP = Nothing
End If
End If
End Sub
-----Original Message-----
Can someone point me in the right direction or supply a snippet of code?
Here's what I want to do:

A new email comes in to an Outlook 2002 client that gets its mail from a
POP3. VBA code runs to determine the address of the sender and if it's one
of a select number of addresses, it replies
automatically to the message and
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top