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: 601

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
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
T Problem when requesting to view an email in a browser Using Outlook 0
J Outlook 365 Forward Email Subject to my inbox when new email arrive in shared inbox Using Outlook 0
HarvMan Archive Email Manually Using Outlook 0
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
S New Email "From" box stopped working Using Outlook 0
Rupert Dragwater Duplicate email in Folder Using Outlook 7
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
MattC Changing the font of an email with VBA Outlook VBA and Custom Forms 0
L Specific Incoming Email Address Immediately Deleted Using Outlook 2
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Edit contact from email does not open the user defined contactform Using Outlook 3
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
R Roadrunner Email Settings | Contact Roadrunner Customer Support Outlook VBA and Custom Forms 1
D Gmail mail is being delivered to a different email inbox in Outlook App 2021 Using Outlook 2
Albert McCann Outlook 2021 Outlook Display of HTML Email from two senders is glitchy Using Outlook 0
A How Do I Setup My Optonline.Net Email Account? Outlook VBA and Custom Forms 1
H Preventing the 'email address fetch from Exchange' crashing email reading code Exchange Server Administration 0
D multiple email accounts - why do I have to choose the "from" account address?? Using Outlook 2
Wotme create email only data file Using Outlook 1
F Outlook 2016 Email with attachments not being received Using Outlook 3
J Outlook 2019 Regex email addresses from body Outlook VBA and Custom Forms 6
D Prompt to prefix subject line whenever sending an email Outlook VBA and Custom Forms 3
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
C Wishlist Extract or scan new email addresses from out of office replies. Leads from OOO replies Using Outlook 1
T External email warning banner Outlook VBA and Custom Forms 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 5
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

Similar threads

Top