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.
 
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?
 
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
 
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
 
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: 654
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.
 
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 :(
 
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
 
Did you set a reference to the Microsoft VBScript Regular Expressions 5.5 library in Tools, References (in the VB Editor)?
 
oops, i missed that - either use
myForward.Recipients.add =
or
myForward.to =
 
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
 
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.
 
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.
 
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
 
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.
 
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.
 
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
P Email address auto-completes work fine on laptop, but no longer on desktop Using Outlook 2
S Create Outlook Task from Template and append Body with Email Body Outlook VBA and Custom Forms 4
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
A Search folder and move the email Outlook VBA and Custom Forms 0
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
farrissf Outlook 2016 Optimizing Email Searches in Outlook 2016: Seeking Insights on Quick Search vs Advanced Search Features Using Outlook 0
D Delete selected text in outgoing email body Outlook VBA and Custom Forms 0
F Graphics in email / Mac recipient garbled Using Outlook 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 1
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
S Email Macros to go to a SHARED Outlook mailbox Draft folder...NOT my personal Outlook Draft folder Using Outlook 2
R Outlook 365 VBA AUTO SEND WITH DELAY FOR EACH EMAIL Outlook VBA and Custom Forms 0
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
C Spam Email? Using Outlook 2
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
E Save Selected Email Message as .msg File - digitally sign email doesn't works Outlook VBA and Custom Forms 1
S Email was migrated from GoDaddy to Microsoft exchange. We lost IMAP ability Exchange Server Administration 1
R Outlook 365 How to integrate a third-party app with Outlook to track email and sms? Using Outlook 2
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
Rupert Dragwater How to permanently remove an email address Using Outlook 9
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
F Auto changing email subject line in bulk Using Outlook 2
F Want to add second email to Outlook for business use Using Outlook 4
kburrows Outlook Email Body Text Disappears/Overlaps, Folders Switch Around when You Hover, Excel Opens Randomly and Runs in the Background - Profile Corrupt? Using Outlook 0
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Shift Delete doesn't delete email from server Using Outlook 3
K Incorporate selection from combobox into body of email Outlook VBA and Custom Forms 0
L Why are some email automatically going to "archive" Using Outlook 2
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
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 1
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 1
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

Similar threads

Back
Top