Foward email to Trello without FW in subject and parce the text

Status
Not open for further replies.
Outlook version
Email Account
IMAP
I have read and tried to use several of the threads that you have already answered but not sure exactly what to do to put them all in the right order. I'm trying to auto forward using a rule to an email address that TRELLO gives for one of my project boards. The rule works because I can see them all go out but i think they are getting stopped because of the amount and because they have FW in the subject so I'd like to remove the FW in the subject and it would be nice if the subject could be changed to the string of text that is in the body of the email located after a cc-severalnumbers and a space "string of alphanumeric" return

Also would like to only forward the body of the email after the words "a summary of your request follows" to the end of the email. I have copied the change subject then forward but just don't know how to put it all together.
 
Outlook version
Email Account
IMAP
I think regex will work to capture the text - a sample is here:
http://www.slipstick.com/developer/regex-parse-message-text/#comment-181863

Assign the values to a string -
Dim strSubject(2) As String '2 = number of case statements
then get each string
strSubject(i) = M.SubMatches(1)

strNewSubject = strSubject(1)
strBody = strSubject(2)


I've spent alot of time on that page and I'm just not sure it answers what I'm trying to do so let me rephrase.
I don't think I need to pick up text specifically with the .Pattern = "Due Date\s*[:]+\s*([\w-]*)" because I want to capture everything after the "a summary of your request follows" to put in the body..

But more importantly and this is the part I cant seem to figure out from that link is I would like to capture the information listed after cc- so would it look like this?
.Pattern = "(cc\s*[-]\s*(\d+\.\d+)\s*)" and if so how does that get captured to become the new subject?
 
Outlook version
Email Account
IMAP
This is what I was working on but i'm confusing to many different suggestions that I think I've got it messed up bad!


Sub ChangeSubjectForwardandbody(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 = "(cc\s*[-]\s*[0-9]\s*(\d+\.\d+)\s*)" <-- This is where I wan to capture the new subject!
.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 = "(follows\s*[:]+\s*(\w*)\s*)" <--This is where I want to capture everything to the end of the message to use as the body of the new email!
.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 = Reg1
'Item.Save
Set myForward = Item.Forward
myForward.Recipients= “jharris@bluelinedesign.org" <--This is where I want the messages to go without the "FW" on the subject line.
myForward.Subject = Item.EntryID <--This is supposed to equal the new subject I captured after the cc-2356923 (space) "new email subject"

myForward.Display 'Send

Set oItem = Nothing

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Let's start with this - because you can run it on a selected message and check the values in the Immediate windows (Ctrl+G or look in the View menu.)

Once you get the pattern down, you can convert it to a script to use in a rule. I'm not sure if the pattern is correct, mostly because I don't have a message to test it on.

Code:
Sub ForwardMessageChanges()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strResult(2) As String
Dim strSubject, strFollows As String
Set Reg1 = New RegExp
Set olMail = Application.ActiveExplorer().Selection(1)

For i = 1 To 2
strResult(i) = ""
With Reg1
Select Case i
Case 1
.Pattern = "(cc\s*[-]\s*[0-9]\s*\n(\d+\.\d+)\s*)" ' try \n or \r if you need to get a value from the next line
.Global = False
Case 2
.Pattern = "(request follows(.*)[:]\s*(.*)).\s*\n"
.Global = False
End Select
End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)

For Each M In M1
strResult(i) = M.SubMatches(1)
Debug.Print i & ": " &  strResult(i)

strSubject = strResult(1)
strFollows = strResult(2)

Next
End If

Next i

Set myForward = olMail.Forward
myForward.Recipients= “jharris@bluelinedesign.org" <--This is where I want the messages to go without the "FW" on the subject line.
myForward.Subject = strSubject <--This is supposed to equal the new subject I captured after the cc-2356923 (space) "new email subject"
myforward.body = strFollows
myForward.Display 'Send

Set Reg1 = Nothing
Set olMail = Nothing
Set M1 = Nothing
Set M = Nothing
End Sub
 
Outlook version
Email Account
IMAP
Ok I put that into a new module and saved it as change subject forward.
Then I created a new rule in outlook 2007 that looks like this:
upload_2014-10-1_16-41-3.png

and it looks like the messages are moved to the service request folder and marked with the projects category but I don't see anything in sent box and nothing came in Trello.

Here is a sample of what the email would look like as it comes in.
upload_2014-10-1_16-46-33.png


Thanks so much for your help. I'm really all twisted in my logic now.
 

Attachments

  • upload_2014-10-1_16-40-4.png
    upload_2014-10-1_16-40-4.png
    61.1 KB · Views: 571

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The rule should be conditions only - the only action should be the script - assign the category and move it using the script.

I think what is happening is it gets moved and outlook loses track of it for the script. it might help if you grab the entryid and use that to identify the object, but the rules can be buggy and fail if you have conditions in with a script - its really better to hand off to a script.
 
Outlook version
Email Account
IMAP
The rule should be conditions only - the only action should be the script - assign the category and move it using the script.

I think what is happening is it gets moved and outlook loses track of it for the script. it might help if you grab the entryid and use that to identify the object, but the rules can be buggy and fail if you have conditions in with a script - its really better to hand off to a script.


Ok but I'm not sure I know how to do it within the script :(
 
Outlook version
Email Account
IMAP
Ok here is what I have so far based on your suggestions and what I've been able to gleen from the websites..
It still gives me a compile error: User-defined type not defined

Here is the code:
Sub ForwardProjectcard()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strResult(2) As String
Dim strSubject, strFollows As String
Set Reg1 = New RegExp
Set olMail = Application.ActiveExplorer().Selection(1)

For i = 1 To 2
strResult(i) = ""
With Reg1
Select Case i
Case 1
.Pattern = "(cc\s*[-]\s*[0-9]\s*\n(\d+\.\d+)\s*)"
.Global = False
Case 2
.Pattern = "(request follows(.*)[:]\s*(.*)).\s*\n"
.Global = False
End Select
End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)

For Each M In M1
strResult(i) = M.SubMatches(1)
Debug.Print i & ": " & strResult(i)

strSubject = strResult(1)
strFollows = strResult(2)

Next
End If

Next i

Set myForward = olMail.Forward
myForward.Recipients = "nameofmyboard@boards.trello.com"
myForward.Subject = strSubject
myForward.Body = strFollows
myForward.Send

Set Reg1 = Nothing
Set olMail = Nothing
Set M1 = Nothing
Set M = Nothing

'Assigns Category to Mailitem
Item.Categories = "Projects"
Item.Save
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Did you set a reference to the Microsoft VBScript Regular Expressions 5.5 library in Tools, References (in the VB Editor)?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
oops, i missed that - either use
myForward.Recipients.add =
or
myForward.to =
 
Outlook version
Email Account
IMAP
oops, i missed that - either use
myForward.Recipients.add =
or
myForward.to =
Ah... ok so changed to myforward.to =""
and Now getting a run-time error '424': Object required
Does the strResult (i) = "" need to have something in it?

Here is the code just to make sure I didn't change something...
Sub ForwardProjectcard()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strResult(2) As String
Dim strSubject, strFollows As String
Set Reg1 = New RegExp
Set olMail = Application.ActiveExplorer().Selection(1)

For i = 1 To 2
strResult(i) = ""
With Reg1
Select Case i
Case 1
.Pattern = "(cc\s*[-]\s*[0-9]\s*\n(\d+\.\d+)\s*)"
.Global = False
Case 2
.Pattern = "(request follows(.*)[:]\s*(.*)).\s*\n"
.Global = False
End Select
End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)

For Each M In M1
strResult(i) = M.SubMatches(1)
Debug.Print i & ": " & strResult(i)

strSubject = strResult(1)
strFollows = strResult(2)

Next
End If

Next i

Set myForward = olMail.Forward
myForward.To = "jharris@bluelinedesign.org"
myForward.Subject = strSubject
myForward.Body = strFollows
myForward.Send

Set Reg1 = Nothing
Set olMail = Nothing
Set M1 = Nothing
Set M = Nothing

'Assigns Category to Mailitem
Item.Categories = "Projects"
Item.Save
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
another oops... i didn't notice this:
'Assigns Category to Mailitem
Item.Categories = "Projects"
Item.Save

that needs to be olmail, not item.[DOUBLEPOST=1412274900][/DOUBLEPOST]or, change all instances of olmail to item.
 
Outlook version
Email Account
IMAP
another oops... i didn't notice this:
'Assigns Category to Mailitem
Item.Categories = "Projects"
Item.Save

that needs to be olmail, not item.[DOUBLEPOST=1412274900][/DOUBLEPOST]or, change all instances of olmail to item.
You rock Diane. Thank so much for your help.
I just realized I didn't add move to folder in there.. I could run a rule to move them over to the folder and then run this script on everything that gets put in that folder unles you have a better option.
 
Outlook version
Email Account
IMAP
Actually the email is sent and the subject is BLANK and the contents is BLANK and only the first one gets category assigned. But IT DID RUN! ug.

Sub ForwardProjectcard()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strResult(2) As String
Dim strSubject, strFollows As String
Set Reg1 = New RegExp
Set olMail = Application.ActiveExplorer().Selection(1)

For i = 1 To 2
strResult(i) = ""
With Reg1
Select Case i
Case 1
.Pattern = "(cc\s*[-]\s*[0-9]\s*\n(\d+\.\d+)\s*)"
.Global = False
Case 2
.Pattern = "(request follows(.*)[:]\s*(.*)).\s*\n"
.Global = False
End Select
End With

If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)

For Each M In M1
strResult(i) = M.SubMatches(1)
Debug.Print i & ": " & strResult(i)

strSubject = strResult(1)
strFollows = strResult(2)

Next
End If

'Assigns Category to Mailitem
olMail.Categories = "Projects"
olMail.Save

Set myForward = olMail.Forward
myForward.To = "username@boards.trello.com"
myForward.Subject = strSubject
myForward.Body = strFollows
myForward.Send

Next i

Set Reg1 = Nothing
Set olMail = Nothing
Set M1 = Nothing
Set M = Nothing


End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This code is for the selected message - as in only one message - so that is expected. I'm guessing the regex is the problem. I'd delete or comment out the new message code and watch the immediately window (or change debug.print to msgbox) so you can see if its picking anything up.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You rock Diane. Thank so much for your help.
I just realized I didn't add move to folder in there.. I could run a rule to move them over to the folder and then run this script on everything that gets put in that folder unless you have a better option.
Assuming you want this automated...
Once this code works, we can convert it to a run a script so it can work in a rule. Or you can use the rule to move the mail and use an itemadd to run the code. Either are fairly simple tweaks - but slow down testing. Getting the regex correct is hard part and its just faster to test it with manual code.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
since you want everything after the cc number, try this - it might be case sensitive so use the proper case for the cc (i forget :))

.Pattern = "cc-(\d*)\s*(.*)"

you might need to use
.MultiLine = True
with case 2. put it after the .global = false line.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Appending text to the subject line of a Reply, Foward or new Email Outlook VBA and Custom Forms 2
Diane Poremsky Foward a Message and CC the Original Recipients Using Outlook 0
A Links in email getting error message about group policy Using Outlook 4
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 1
J Recommendations for Outlook Duplicate Email Remover Using Outlook 6
Geldner Tweak Junk Email Reporting tool to default to particular email on send? Using Outlook 3
S Outlook 365 Can I change the possible range of highlighting colours when writing an Outlook email? Using Outlook 1
V Can one change the formatting of email title blocks? Using Outlook 0
P default font when sending email from browser Using Outlook 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
B IMAP server rejects sent email - cannot deliver messages Using Outlook 2
TedSch Small vba to kill political email Outlook VBA and Custom Forms 3
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i Email notifications changed with Outlook 2021 Using Outlook 8
glnz How to retrieve or redo Verizon.net email password without affecting Outlook connection? Using Outlook 1
Z Copy specific email body text Outlook VBA and Custom Forms 0
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
M Outlook 365 refuses to send email Using Outlook 1
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
K Closing external IMAP email... Outlook 2013 Using Outlook 0
L Capture email addresses and create a comma separated list Outlook VBA and Custom Forms 5
C Email bomb processing Outlook VBA and Custom Forms 1
O What would be the recommended way to change an email address (family member)? Using Outlook 0
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0
L Checking Sender Email Address for trusted domain from list on intranet Outlook VBA and Custom Forms 4
J How do you disable address search box when typing @ in body of email? Using Outlook 0
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
Victor.Ayala Automated way to check the option "Show this folder as an email Address Book" Outlook VBA and Custom Forms 2
D Wrong email address in Outlook 2003 "From" tab in new outgoing emails Using Outlook 4
D Forwarding email based on the attachment file type and specific text found on the attachment file name Outlook VBA and Custom Forms 1
F Forward incoming email with 4 embedded images in the body without original sender Outlook VBA and Custom Forms 22
W Macro to Filter Based on Latest Email Outlook VBA and Custom Forms 6
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
C Outlook 2007 Removing then adding account restores junk email processing Using Outlook 0
G Place jpg in body of email Outlook VBA and Custom Forms 1
F Wishlist Outlook suddenly began synchronizing deleted items every time I delete a single email. Using Outlook 2
N Save Selected Email Message as .msg File Outlook VBA and Custom Forms 12
HarvMan Toggle between calendar and email in Outlook 365 Using Outlook 12
F Email being marked as Spam by Gmail and not being visible in Outlook Using Outlook 5
G Email time stamp Using Outlook 2
G Schedule recurring email and attachments display Outlook VBA and Custom Forms 3
G Save and Rename Outlook Email Attachments Outlook VBA and Custom Forms 0
B Need to Copy an email to a subfolder Outlook VBA and Custom Forms 2
M How to setup outlook after importing old account information - Entering email account info creates with "(1)" after the account! Using Outlook 1
K Multiple Rules on Single Email Using Outlook 2
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
e_a_g_l_e_p_i Outlook 2010 How to set default email address for website links Using Outlook 3
O Same email address, same person, names in so many ways Using Outlook 4
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10
D Outlook launch email showing new unread email in reading pane Using Outlook 11

Similar threads

Top