Reply rule with certain word in subject

G

Guest

Hi,

I wonder if some kind person would be able to help me on this one.

I need to create a rule that will reply to every email I receive with a
certain word in the subject line. Even if someone sends 2, 3 or 20 emails
from the same address. I also need to send back a specific template and an
attachment.

Basically, I can do this using the normal rules but it only replies once to
a unique address.

Any ideas on the VB code needed to do this or if one is already created that
I can use?

Version Outlook 2003.

Please feel free to email me: (e-mail address removed)

just remove the DELETETHIS to email me.

thanks in advance of any help!

Andy Jones
 
M

Michael Bauer

Hi Andy,

with a few modifications you can use the following code. In
AutoReplyToSubjectWithSpecificTemplate you need to fit the variables
sSubjectTemplate and sLookFor.

The sample presupposes that you have an e-mail template with all needed
attachments saved in the drafts folder.

Anyway, note that OL won´t fire the ItemAdd event for the Inbox if there
are more than 16 mails coming in at once.


'<DieseOutlookSitzung>
Private WithEvents Items As Outlook.Items

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

Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
AutoReplyToSubjectWithSpecificTemplate Item
End If
End Sub

Public Sub AutoReplyToSubjectWithSpecificTemplate(oMail As
Outlook.MailItem)
On Error Resume Next
Dim oReply As Outlook.MailItem
Dim lPos As Long
Dim lStartPos As Long
Dim sLookFor As String
Dim sSubject As String
Dim sSubjectTemplate As String

sSubjectTemplate = "subject of template"
sLookFor = LCase$("subject of incoming mail")
lStartPos = Len(sLookFor)

sSubject = oMail.Subject
If LCase$(left$(sSubject, lStartPos)) = sLookFor Then
Set oReply = GetTemplate(oMail.Session, sSubjectTemplate)

Select Case oMail.ReplyRecipients.Count
Case 0
oReply.To = oMail.SenderName
oReply.Recipients.ResolveAll
Case Else
CopyRecipients oMail.ReplyRecipients, oReply.Recipients
End Select

oReply.Subject = "Re: " & oMail.Subject
oReply.Send
End If
End Sub

Private Function GetTemplate(oSess As Outlook.NameSpace, _
sSubject As String _
) As Outlook.MailItem
Dim oFld As Outlook.MAPIFolder

Set oFld = oSess.GetDefaultFolder(olFolderDrafts)
Set GetTemplate = oFld.Items.Find("[subject]='" & sSubject & "'")
End Function

Private Sub CopyRecipients(oSource As Outlook.Recipients, _
oDest As Outlook.Recipients _
)
Dim oRecip As Outlook.Recipient

For Each oRecip In oSource
oDest.Add oRecip.Name
Next
oDest.ResolveAll
End Sub
'</DieseOutlookSitzung>
 

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