Want to forward a template email with an email address contained inthe trigger email

C

Casey Sheldon

I'm trying to automate a process wherein an email comes in with a
certain Subject, then a regex pulls an email address out of that
trigger email, and sends a template to that email address. What I have
so far is somewhat mangled. Please help?

Sub CustomMailMessageRule(Item As Outlook.MailItem)
Dim myolApp As Outlook.Application
Dim myItem As Outlook.MailItem
Dim mySend As Outlook.MailItem
Set myNamespace = myolApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set myolApp = CreateObject("Outlook.Application")
If Not myFolder.Items = 0 Then
Set myItem = myFolder.Items(1)
myItem.BodyFormat = olFormatPlain
Set mySend = myolApp.CreateItemFromTemplate("C:\template.oft")
With mySend
.Recipients = RE6(myItem.Body)
.Subject = "Blahdy blah"
End With
' mySend.Send
End If

End Sub

Function RE6(strData As String) As String
Dim RE As Object, REMatches As Object
Set RE = CreateObject("vbscript.regexp")
With RE
.MultiLine = True
.Global = False
.IgnoreCase = True
.Pattern = "(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)"
& _
"|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-
Z]{2,6}"
End With

Set REMatches = RE.Execute(strData)
RE6 = REMatches(0)

End Function

Haven't used vb since vb6, and I guess it probably shows. Thanks in
advance for any help.
 

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