Create script to forward emails adding text and changing subject line

Hello all:

We have hybrid O365/On-Premise environment. I have an O365 shared mailbox that receives transcribed voicemails.  What I would like to do is create a script that will look in a folder (perhaps the inbox) and when a transcribed voicemail email come it, it will do the following:

1) Change the subject line
2) Add some text to the end of the email
3) Forward the email to another mailbox

So basically I need a watcher script that will watch an inbox, and when this type of email comes in it will process it into a case.
LVL 15
Juan OcasioApplication DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Riaz Alexander AnsaryEnterprise Infrastructure Systems EngineerCommented:
this can easily be done via transport rules. based on what you described above I have constructed a quick rule for you that will do just what you need. refer to screenshot bellow:
Expert.jpg.png
  1. you chose any condition for your message to identity what message you want the rule to apply. in this case any message that the subject line includes the word voicemail.
  2. You can chose your first actions here which in this case changes the subject line and adds voicemail to the beginning of it.
  3. You can chose your second action here which adds a message to the body of the email.
  4. once you chose your second action in number 3, here is where you add your text.
0
Juan OcasioApplication DeveloperAuthor Commented:
Sadly, there is no way to to forward.  We could forward for approval.  Also, want to change the subject line, not prepend.  We tried this route and no go.
0
Juan OcasioApplication DeveloperAuthor Commented:
Also, as an aside, the appending disclaimer is not consistent.  In our tests (we tried this route ) it would not always append it.  In fact, it left it off most of the time.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Riaz Alexander AnsaryEnterprise Infrastructure Systems EngineerCommented:
if its setup right with all conditions you and actions it has no reason to break and yes you can forward message via transport rules. but if you wana go via powershell roue, there will be a lot of script and object manipulations to try to get exactly what you want.
I would start thinking with using search-mailbox to search mailboxes or a particular mailbox for a -searchquery or whatever you want and then if it finds it you use send-mailmessage to construct the email you would want to send this command comes with all parameters you would need. the only tricky part will be extracting the accrual email and using that as the original email, which will requires over thinking and finding different options and ways and chose the best one.  you got to start working on a scrip and the idea and post your code here for any questions and brainstorming.  you will not get someone just like that to write  you a complete code :). If i had something written like i usually do anything AD or exchange related i would share it with you like i share them on technet gallery.
Its a pretty good idea tho :). BUT again you should be able to do this just fine via transport rules.
0
Juan OcasioApplication DeveloperAuthor Commented:
Thanks.  Using the transport rule, how do you change the subject line?  Also, which rule do you use to forward?  I believe there was a forward before, but now we only have redirect and forward for approval.
0
Riaz Alexander AnsaryEnterprise Infrastructure Systems EngineerCommented:
You can use any of the boxes 1, 2 to work the forwarding, redirect should work as forwarding or to the Bcc. however for subject the only way you can do is the box 3 which only prepends the subject line and not replacing it. DO you guys have to change the entire subject?
what we usually do here at my current job do subject strip and changes in our messaging gateway which we are using Proofpoint. not sure if you guys have any type of messaging security gateway like ironport, proofpoint or trend. you can set more robust rules in there before it even hit the exchange servers.

Expert1.png
0
Juan OcasioApplication DeveloperAuthor Commented:
Yes, we have to change the subject line although we were looking at prepending which might work, however,  unfortunately, we cannot use redirect as it removes the original recipient.  We have to forward from the mailbox, not redirect the mail entirely.
0
Alexei KuznetsovMicrosoft Outlook MVPCommented:
Do you need a server-side only solution or client-side is ok?
0
Juan OcasioApplication DeveloperAuthor Commented:
Server side would be ideal, but client side may be ok.  Only issue I'll have to figure out is how to run it on the client; we have run macro rule disabled and the mailbox is shared, so I don't want it attached to any one person.
0
Juan OcasioApplication DeveloperAuthor Commented:
I have found a solution.  I am creating a c# console app that will use Exchange Web Service API to accomplish this task.  I will then use a scheduled task to run it every 5 to 15 minutes (still discussing this last point with my core system's team).

Thanks to all for the input you contributed.

Juan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Juan OcasioApplication DeveloperAuthor Commented:
summarized in comment
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.