Double move of emails


I am building a workflow that interacts with outlook and moves emails. It is doing the first move, to the processing folder, without issue. However, the second move, to the processed folder, is failing. I am using the same mail message variable from start to finish.

Is it possible to make the second move? I have fundamental issues with having to do another “get” on the processing folder because the UID will change after the first move.

are we trying to move the same or different one
Kindly elaborate the process been carried out so that we could go in right direction
Cheers @SoqedHozi

Same email.

It moves the email from the inbox to the subfolder “Inbox\Processing”. It subsequently moves the same email from “Inbox\Processing” to “Inbox\Processed”.

I am hoping, and in some way was expecting, the variable to know the email id and therefore be capable of moving it a second time.

1 Like

For this we need to read the mail from that folder using get outlook mail activity with the folder property mentioned with value “Inbox\Processing and then only we can make a move with move mail activity where the destination folder mentioned as “Inbox\Processed”.

Cheers @SoqedHozi

In that case how would I match the email in processing to the original email in the inbox, to make sure I am moving the correct one?

along the sequence first we are going to get the mail first with folder mentioned as “Inbox” along the property
–then move it to folder “Inbox\Processing” using move mail activity
–then we are going to use again get outlook mail activity but this time with folder mentioned as “Inbox\Processing” and disabling the property onlyunreadmessage in the property panle of get outlook mail activity and put the property TOP as 1
–then we are going to use move mail activity to send that single fetched mail using move mail activity but with destination folder as “Inbox\Processed”

simple isn’t it
hope this would help you
Cheers @SoqedHozi

Doesn’t this limit the initial get to 1 email as well? What if the emails aren’t being moved the second time in the order they were received?

You see, we have an additional process that decides what happens to the emails. That process returns the UID of the original email so we can match it up, and it isn’t always in the same order as they were saved from the inbox (especially as the save name is the UID). We have to pick from the processing folder each email according to the result - processed, forwarded, reviewed only or indeed not moved (stuck in processing).

An example-

  • Emails 1,2,3 come in and are saved and moved to processing
  • Results come back for emails in the order 2,1,3
  • Email 2 is moved to processed, email 1 is not moved, and email 3 is moved to forwarded

The only solution I can think of other than doing 1 email at a time (which is really inefficient) is to use a log table to store the UID of the original email and a new UID for the moved email in an additional column, though this system requires the order of emails moved from Inbox to Processing to be unchanged and the emails to only be marked read after the second “get”.

My assumption had been of course that the location of the email in mailmessages (which it knows in order to make the first move) would be updated automatically as the move takes place, allowing the second move.

Collections, like the mailmessages is moment in time. Once its moved, it is lost (and the object isn’t updated). Especially if time is passing (other processes can act on the objects, and you can end up with exceptions for null reference). There will be no way around populating a new collection.

Also, tracking the UID (b/c I think its similar to getHashCode in that its a group reference) may not work, in that if other emails go in/out it might change (as the getHashCode does), but I have not tested this, so you should double check if you decide track this way.

How do the other workflows know what the results are for which emails? You’ll need a different way to determine what makes your email unique. How often do the emails come in? could Date header work?

The problem with date is volume, and emails regularly coming in at the same time.

The plan I suppose then is to use the UID in that moment in time, which allows me to match emails in the collection to responses, and then use an associations table to match these up to the emails in the new location (which will remain unread until the second get).

My current match process is on UID. i read the UID from the results (which was sent as file name and in the header of course) and match it up to the email in the collection. This allows me to perform the actions I need to in our system. he stumbling block is then moving the email to it’s final location, which would need to be matched using the association table as above.

The process isn’t perfect as clicks seem to be missed and type intos aren’t actioning, despite these working in other workflows! That’s a separate issue that I need to solve!

@SoqedHozi - ok, so, instead of using UID, which changes when the email is moved - what about comparing static pieces of info combined to make unique, like:

or email.Subject+email.Body+email.Headers("Date")


As a unique identifier. You could even turn it into a Hash (which won’t change, since the text is static) in case the amount of text is really high:

or (email.Subject+email.Body+email.Headers("Date")).GetHashCode

I think that would serve the same purpose as the UID but woulnd’t chage when email is moved. I tested the theory, by hashing email.Body and those hashes matched after the file was moved:

BlankProcess2 execution started
One: -507033902 **<---Hash of email body in Inbox**
*{move code to new folder executed here}*
Two: -507033902 **<-- Hash of email body after second "Get messages" call on new folder**
Found Email -507033902 **<-- If test against email.body.GetHash = intInitialHash**
BlankProcess2 execution ended in: 00:00:01
1 Like

An elegant solution, and saves me using an extra table! My only concern is if there are two identical emails at the same time. In this case the hash would match, and only one email would be saved/returned. I can write a try/catch for if the name already exists to save it differently, and then when the returns come back and don’t match a human can deal with the “duplicate” manually. I’d expect this to be rare especially if sender email is included in the hash. Only autoreplies would cause duplicates then.


@SoqedHozi - Thank you!

You could add more info. Example, not only do you have the properties exposed by the MailMesasge object, but you have headers as well, like:


I’ve made changes, using mail.Subject.GetHashCode.ToString+mail.Body.GetHashCode.tostring+mail.Headers(“Date”)

I then use a get, for each and if to get the right email from the processing folder.

I have a concern regarding hash, in that two emails could have the same hash. My concerns are both in saving the emails (as ID.msg) as save as does not give the option to overwrite, and in matching after the response is returned, Further to this last point, I would have a log of all emails ever and therefore the hash really should be unique. The later is why I have added the date, but is there a solution that solves everything or can put my fears at ease?

Adding datetime, I think, will make it impossible to recreate the hash to determine the hash to compare later.

It will be as unique as the data used to make the hash. So if you have 2 emails that all have the same:

Then yes, those 2 emails would have the same hash - but what are the chances of two emails coming in that are identical, including 3 dates being identical to the second?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.