rule to change subject, pull email addresses from body, and forward with templ

Status
Not open for further replies.

moe0303

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
template.

Hello,

I want to create a rule which will be applied to emails with specifc text in the subject field. I want to "reply" to the email, but I want the reply to go to an email address contained within the message body (not the original sender). I also want to change the subject to "Heat Ticket" and a number pulled from the message body. Once all that is sorted, the rule would send a template to the new email address.

I see the option in the rules to run a script. Can I use that to complete this action? If so, how? I'm not a programer and have very limited code experience.

Thanks in advance for any help you can give.

-Moe
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: rule to change subject, pull email addresses from body, and forward with t

Yes, you would use Run a Script. I have sample scripts available.

Is the address (and number) you want to use easily identifiable in the message? Ie, you can search for a specific word or phrase and the address always follows.

Links to my samples are at Outlook's Rules and Alerts: Run a Script - Slipstick Systems

You'll also need to get the address and number - Use RegEx to extract text from an Outlook email message - Slipstick Systems
 

moe0303

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Re: rule to change subject, pull email addresses from body, and forward with t

Thanks so much for your reply, Diane.

I'm not sure I understand how to implement (or modify) your code for my purposes. The number will always follow the word "Ticket". I would like to pull any email address within the message body. The only thing that I can guarantee will be the same each time is the domain of the email. Using the information from article about extracting text, I came up with the following:

> pattern="(Ticket\s*(\d*)\s*)"

' Starts with "Ticket" + some white space + some digits + white space

> pattern="((\w*)@hotmail.com\s*)"

'starts with some alphanumeric string +"@hotmail.com" + some white space.

Are those correct?

Once I have extracted the text, how do I get the information to do what I want?

==========================================

Sample message:

Ticket 123456789 has been assigned.

please contact moe0303@hotmail.com with any questions.

==========================================

I would want the rule to send a pre-prepared message with the subject "Work Ticket 12345678" to moe0303@hotmail.com.

I know I would have to create a template and I think I can do that, but I don't know how to write the code.

Can this be done?

Thanks again for all your help.

-Moe
 

moe0303

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Re: rule to change subject, pull email addresses from body, and forward with t

Dear moderators,

I apologize for trying to reply to this thread 1000 times. I didn't see the pop-up till just now which says it will have to be approved by a moderator, and I feel like a fool. Please forgive me.

-Moe
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: rule to change subject, pull email addresses from body, and forward with t

Not a problem - I'm not sure what flagged it for moderation...
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: rule to change subject, pull email addresses from body, and forward with t

This code should get you halfway there (assuming I didn't make any stupid mistakes in it, i didn't test it) - i need to check on how to get the address since it's a second pattern rather than part of the number pattern.






Code:

 
 
Sub ChangeSubjectForward(Item As Outlook.MailItem)
 
 

   Dim oItem As Outlook.MailItem
   Dim Reg1 As RegExp
   Dim Reg2 As RegExp
   Dim M1 As MatchCollection
   Dim M As Match
   Dim EntryID As New Collection
   Dim strID As String
 
 

 
 

   Set Reg1 = New RegExp
   Set Reg2 = New RegExp
   
   strID = Item.EntryID
   Set oItem = Application.Session.GetItemFromID(strID)
   
   
   With Reg1
       .Pattern = "(Ticket\s*(\d*)\s*)"
       .Global = True
   End With
   
   If Reg1.test(oItem.Body) Then
       Set M1 = Reg1.Execute(oItem.Body)
       For Each M In M1
         strCode = M.SubMatches(1)
       Next
   End If
   
   With Reg2
       .Pattern = "((\w*)@hotmail.com\s*)"
       .Global = True
   End With
 
 

   If Reg2.test(Item.Body) Then
       Set M1 = Reg2.Execute(Item.Body)
       For Each M In M1
         strAlias = M.SubMatches(1)
       Next
   End If
   
   

 
 
'--------------

'Item.Subject = "Heat Ticket " & strCode
'Item.Save

 
 
Set myForward = Item.Forward
 
 

myForward.Recipients.Add strAlias & "@hotmail.com"
myForward.Subject = "Heat Ticket " & strCode
 
 

 
 
myForward.Display 'Send
 
 

 
 

 
 
Set oItem = Nothing
 
 

 
 
End Sub





- - - Updated - - -




BTW, for testing, i have it set to display the message rather than send it.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: rule to change subject, pull email addresses from body, and forward with t

I updated the code above - it worked in a simple test here. I changed it so the subject is changed only in the forward and FW is removed. If you want the FW, use the original line which i commented out.
 

moe0303

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Re: rule to change subject, pull email addresses from body, and forward with t

I'm getting a "user defined type not defined" error on the following line: Dim Reg1 As RegExp

:(

Is RegExp something I have to install?
 

moe0303

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Re: rule to change subject, pull email addresses from body, and forward with t

Awesome! Sorry I missed that part.

I actually like having it display the message for now.

Now, how do I get it to pre populate a message? I have a template named "Review" if that helps.

Thanks again for your help.

-Moe
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: rule to change subject, pull email addresses from body, and forward with t

you'll need a slightly different code for below the '---- line in the macro - from Run a Script Rule: Send a new message when a message arrives - Slipstick Systems

instead if

Set myForward = Item.Forward
myForward.Recipients.Add strAlias & "@hotmail.com"
myForward.Subject = "Heat Ticket " & strCode

myForward.Display 'Send

Set oItem = Nothing

use

Dim objMsg As MailItem

Set objMsg = Application.CreateItemFromTemplate("C:\path\to\review.oft")

objMsg.Recipients.Add strAlias & "@hotmail.com"

objMsg.Subject = "Heat Ticket " & strCode

objMsg.display '.Send

Set objMsg= Nothing
 

moe0303

Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Re: rule to change subject, pull email addresses from body, and forward with t

Thank you so much.




It's working great except for one little quirk. If the email address uses a ".", it wont catch the whole first part. For example, some people use their first.mi.last@hotmail.com. and it only catches last@hotmail.com.




I tried switching the \w* to \W*, but that didn't work either.


Any advice?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: rule to change subject, pull email addresses from body, and forward with t

Try
.Pattern = "(([a-z0-9.]*)@hotmail.com\s*)"




That works as i just tested it. (.*) works too, but it gets the entire line - Outlook resolves what it sees as the address but but the display name looks awful




results.png
 

snoopyb98

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Re: rule to change subject, pull email addresses from body, and forward with t

Hi,

What I'm wanting the script to do is this: extract the email address from an email, which is listed after "Email Address:" in the email, create a new message in which the recipient is that extracted email address with a new subject and the body of the email to be from an oft, then sent.

So, I need a little help. I have formulated a script with the information here, part of it worked one time, I made an adjustment, then the script doesn't seem to work at all, or do anything, but there are no errors that it brings up. This is what I have:

PHP:
Sub First(Item As Outlook.MailItem)
   Dim oItem As Outlook.MailItem
   Dim Reg1 As RegExp
   Dim Reg2 As RegExp
   Dim M1 As MatchCollection
   Dim M As Match
   Dim EntryID As New Collection
   Dim strID As String
   Set Reg1 = New RegExp
   Set Reg2 = New RegExp
 
   strID = Item.EntryID
   Set oItem = Application.Session.GetItemFromID(strID)

  With Reg1
       .Pattern = "(Email Address:\s*(\d*)\s*)"
       .Global = True
   End With
 
   If Reg1.test(oItem.Body) Then
       Set M1 = Reg1.Execute(oItem.Body)
       For Each M In M1
         strCode = M.SubMatches(1)
       Next
   End If
 
   With Reg2
     
       .Pattern = "([a-z0-9.]*)@([a-z0-9.]*)"
       .Global = True
   End With
   If Reg2.test(Item.Body) Then
       Set M1 = Reg2.Execute(Item.Body)
       For Each M In M1
         strAlias = M.SubMatches(1)
       Next
   End If
 
  
 
'------------ 
 'Item.Subject = "New Subject Title" & strCode
'Item.Save 
 
Set oItem = Nothing 
 
Dim objMsg As MailItem 
 
Set objMsg = Application.CreateItemFromTemplate("C:\Documents and Settings\Name\My Documents\First Email.oft") 
 
objMsg.Recipients.Add strAlias & "[a-z0-9.]*)@([a-z0-9.]*)" 
 
objMsg.Subject = "New Subject Title" & strCode 
 
objMsg.Display '.Send 
 
Set objMsg = Nothing 
 
End Sub
Any and all help would be greatly appreciated. I've dabbled in writing scripts before, but I'm by no means proficient in them. They are great when they work!

Thanks!
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
V rule to Find some words in the subject, change subject then forward Using Outlook 1
A Change order of actions in one (!) rule Outlook VBA and Custom Forms 2
B Change identity or "from" field if a rule matches Outlook VBA and Custom Forms 14
N Autoresponder won't send to 'noreply@...' and need to change rule to send to on behalf person. Using Outlook 2
J Transport Rule to detect Keyword question.. Exchange Server Administration 2
T "Words In Recipient's Address" Rule Causes Outlook To Stop Processing Rules Using Outlook 3
R Outlook Autoforward rule do not work for NDR messages Using Outlook 1
R Setup autofoward rule on a particular folder in Outlook Using Outlook 0
N Rule for "on behalf of" - with changing names Using Outlook 2
S Unable to remove rule outlook 2010 Using Outlook 0
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
S Adding new Exchange (2016) rule very slow down Microsoft Outlook Exchange Server Administration 0
B Outlook rule run a Script doesn't work Outlook VBA and Custom Forms 1
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
icacream Rule based on sender / wrong sender sent to folder Using Outlook 7
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
L Making rule to move email to folder from one O365 domain Using Outlook 1
J Assess content of User Defined Field in Rule Using Outlook 3
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
J HELP- Rule to auto strip prepend from external emails Using Outlook 0
A Forward Outlook Email by Filtering using Macro Rule Outlook VBA and Custom Forms 44
A rule to flag messages not working Using Outlook 5
Brian Murphy Exchange Online Everything a Transport Rule should do and cannot Exchange Server Administration 1
J Outlook Rules - Changing auto-submit address in multiple rules, according to rule name Outlook VBA and Custom Forms 0
A saving attachement to folder named the same as rule name Outlook VBA and Custom Forms 0
Jennifer Murphy Can I create a Rule with Or'd conditions? Using Outlook 1
A Rules - how to determine if all conditions in rule are true or false Outlook VBA and Custom Forms 5
Vijay Error in rule- Run a script Using Outlook 1
Ascar_CT Rule behavior analysis - any tools available? Using Outlook 0
Liza Creating a rule in outlook to filter messages Using Outlook 0
Stilgar Relsik Create a rule to copy text from an email and paste it in the subject line. Using Outlook 1
M VBA Rule for removing all body but hyperlink then forwarding Outlook VBA and Custom Forms 9
B custome rule Outlook VBA and Custom Forms 2
Diane Poremsky Mark Sent Items as Read After Copying with a Rule New Slipstick.com Articles 0
Diane Poremsky Run a Script Rule: Send a New Message when a Message Arrives New Slipstick.com Articles 2
T Create Rule For Secondary E-Mail Address In Outlook 2016 Using Outlook 4
B Macro To Create Rule To Export From Certain Folder Email Information in one workbook multiple sheets Outlook VBA and Custom Forms 0
C Rule To Save attachments on receipt of email Outlook VBA and Custom Forms 2
Diane Poremsky Create a Task from an Email using a Rule New Slipstick.com Articles 0
ashcosta2 Auto Reply rule based on speficied time Outlook VBA and Custom Forms 0
M Rule option Using Outlook 2
L Run a Script Rule doesn't work Using Outlook 5
O VBA rule on multiple computers using shared mailbox Outlook VBA and Custom Forms 1
J Transactional emails - mail rule Using Outlook 3
M Question: Is there a rule that will save email in Windows Explorer Outlook VBA and Custom Forms 3
S Merge Emails with attachments with inbox rule to forward Using Outlook 5
Similar threads


















































Top