Subscribe to incoming mails for all users (MTA/EWS API or else?) - email

My goal is to develop an Exchange listener that will intercept the organization mail box for new mails and for each mail it would do some logic.
After i've researched the subject online - i saw that there are two primary ways to do that:
Configure a new MTA (Mail Transfer Agent) that will be situated before the exchange server and will intercept the SMTP messages.
Use EWS API to subscribe to a new mail event and run the login on the listener
in this way i have 2 basic problems:
Is there a way to subscribe to all mailboxes on the exchange server? without looping all the users ?
How i can block a client to read his email before my listener handled it ? (can i move the whole incoming mail to a special default folder that the users wouldn't have an access to it - some king of hidden folder ?
Is there other way besides the two that i mentioned to fulfill the demand ?
Thanks!

You can use a Transport Agent on Exchange https://technet.microsoft.com/en-us/library/bb125012(v=exchg.150).aspx which allows you to capture/proces messages while they are in the Transport pipeline. The advantage of this over what you have described in 1. is that you capture every message sent/received on the server including internal messages.
Is there a way to subscribe to all mailboxes on the exchange server? without looping all the users ?
No you need to managed your subscriptions per mailbox folder
How i can block a client to read his email before my listener handled it ? (can i move the whole incoming mail to a special default folder that the users wouldn't have an access to it - some king of hidden folder ?
All clients are equal on Exchange so you cant prioritise a client or block access to a new messages (you can block the client entirely) , in theory you could move all messages that arrive to NON_IPM_Root folder with an Inbox rule which means the user couldn't see them but you might want to consider the implications of what happens when your process fails, this could also be disabled by the user at any time when they create a Inbox rule themselves.

Related

Stop internal read receipts (Outlook 2013)

User wants to send read receipts with all external emails. I've set up a mailbox rule in Outlook to do the following:
Apply this rule after I send the message
notify me when it is read
except if sent to *Bristol* //Dynamic group for office contacts
or except with #"domainname" in the recipient's address
To stop read receipts on internal emails I've set a rule with ECP via "Mail Flow" > Rules to:
IF
the message type is *Read receipt*
AND
The sender is located *Inside the organization*
AND
The recipient is located *Inside the organization*
THEN
Delete the message without notifying anyone
However it is still requesting read receipts for internal contacts.
Outlook and Exchange 2013
Your rule will only stop the delivery of read recipients not the prompting for which is controlled by a property within the message itself.
You could write a Transport Agent https://msdn.microsoft.com/en-us/library/office/dd877026(v=exchg.150).aspx that could do this by basically processing every message that passes through the Hub (or hubs servers) using the TNEF parser find the PidTagReadReceiptRequested and set it false for those Internal recipients. Probalby the best sample for this type of thing would be http://blogs.msdn.com/b/mstehle/archive/2009/01/13/howto-sample-transport-agent-add-headers-categories-mapi-props-even-uses-a-fork.aspx .
The other way that may work is to Setup a Rule Programatically that using the tagAction http://www.dimastr.com/redemption/rdoruleaction.htm#RDORuleActionTag . In theory you should be able to modify a MAPI Property with this action but there are complexities around this and I've never use it.
Cheers
Glen

Automatically moving all mails belonging to same conversation thread to external folder

Hi I have Exchange Server 2007 setup with some users with their own inbox. Since this is all related to office conversations I want to move all the incoming and outgoing mails belonging to same conversation thread to disk folder (any folder on his machine say D:\Conversation1).
I am able to let user create separate disk folder for each conversation and let him move first mail in conversation to this folder. So that is not the problem now.
Also I have written a web app which when provided the conversation ID returns the corresponding disk folder path.
However now what I want is to process all incoming & outgoing mails and auto move them to the disk folder corresponding to their conversation thread. I found two possible ways:
Write Outlook plugin which when user logs in will intercept all incoming mails and outgoing mails find their conversation id, send it to web app I written and move them to the disk folder path returned by my web app.
Using EWS: I could write a service for client machines which will ask for user login and based on that login cred it will connect to Exchange server using Exchange Server Webservices (EWS) and will then do the same thing as above. However here it will require to periodically poll / ask Exchange Server to check if their are any new mails sent / received through by the user who provided the login credentials. In outlook plugin I need not do such periodic requests - I could just write code on new incoming / outgoing mail handlers.
Q. Is there any better approach to achieve this through EWS than as explained above.
Main Q. What I find wrong with both above approaches is that - my functionality is same for all mails accounts / users. So why need user to log in just for movement of mails. Can I write something like Exchange Server Tasks ( - a server side code instead of client side code as it was the case with both above approaches) which will continuously process all mails (from all mail accounts configured on Exchange Server) find their conversation IDs and with the help of my web app move them to the corresponding disk folder.
Details that you may ignore
I have Outlook 2010 configured for users.
I have a repository setup that will manage storage of mails in folder. Yes this repository will be own its own machine - not on the exchange server. But eventually it will be on hard disk, so referring them as "disk folder" is still no wrong.
Also you can think of that web app as a part of repository handling. So it runs on repository machine. Just didn't mentioned above to reduce details and focus on which approaches available and preferable - simple and clean.

Creating a plugin/component that will filter incoming emails on an exchange server?

Is there a predefined protocol / API that will allow me to create a plugin component for exchange (let's say 2007+)?
I need to write a simple spam filter that will communicate with the exchange server and receive every mail that is received by that server. If the mail doesn't pass a check, it will be deleted from the server before being delivered to the user. If it is ok, it will be placed in the user's inbox.
I am looking for a protocol that supports the following:
subscribe to receive a notification whenever an email arrives to the server (before the email is placed in the users' in-box.
get the content of such emails.
have the ability to block further processing on some emails (so they are blocked before reaching the inbox).
Thanks in advance,
May be u can write a transport agent(Exchange Server 2007onwards) which will monitor and act on all the emails flowing through the organisation.
You can get most of the details of an email via a transport agent depending on the event at which u trigger the agent.
Here's a link which gives a thorough documentation.
http://msdn.microsoft.com/en-us/library/exchange/bb204097(v=exchg.150).aspx
You can check body/subject and if it doesn't comply with any of the organisational policy,just clear off all the recipients and the email delivery won't happen.

Can an IMAP client automatically filter messages that an IMAP server receives?

Let's suppose I have created an IMAP client and I want to create a filter that, say, deletes messages that have certain characteristics.
I can make this a startup task that happens whenever the client is opened, but the problen is that a user might view the inbox in a different client and the filter won't get rid of the unwanted messages before the inbox is viewed.
Is there some way to tell the server to call my service every time it receives a message so the unwanted messages can go away once the server receives them instead of once a client is opened? Is this even possible with IMAP? If not, is there a different well supported e-mail technology that allows this sort of interaction?
You can do server-side email filtering with the Sieve Email Filtering Language and the ManageSieve Protocol. There is good support in open-source software. However, I am only aware of a few major email providers, that support it. If it is supported, it is usually accessible on the IMAP host and with the IMAP account credentials, i.e. you can test it by connecting to TCP port 2000 and 4190.
See the following three links for more information:
http://en.wikipedia.org/wiki/Sieve_%28mail_filtering_language%29
https://www.rfc-editor.org/rfc/rfc5228 (Sieve: An Email Filtering Language)
https://www.rfc-editor.org/rfc/rfc5804 (ManageSieve Protocol)
Sieve also supports a few notifications types. If the filtering language is not powerful enough to for your purposes, you can send notifications for all incoming emails, wake up the IMAP client, and let the client to the filtering.

Coldfusion : Listening to the Email messages

I am trying to have a kind of observer pattern in ColdFusion
We want to listen to the incoming Email messages and act on them. Scenario is something like this :
Application sends email to the helpdesk system
Helpdesk system automatically generates a ticket and responds with an email to the email address of the application
The application's email is configured in the Lotus notes
Now the application should listen to this incoming email message, decode that and update the coressponding ticketid
I see there is a possibility with Event Gateways, but I am unable to realize the whole picture.
Thoughts or suggestions?
One way is to setup an email server with IMAP support, and use some sort of polling (every minute, good enough?) in CF using <cfimap> to get the emails.
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WS371453EC-36D5-44ce-BF1E-750E3016BBD6.html
We have a system like this.
We have a postfix server configured to handle mail for a domain. A small script (Perl) on the postfix server places each email on an ActiveMQ queue.
We have a cluster of CF boxes with the ActiveMQ event gateway listener that takes the messages off the queue and processes them using Java Mail.
The delay between postfix receiving the email and a CF server processing it is generally under 1s.
We needed to do it this way for a number of reasons, processing delay being one of them, dealing with a large cluster of CF which made the POP/IMAP solution complicated, and CF's mail handling not being quite what we wanted were others.
It works great.
I've created similar applications in the past using cfpop to interogate a mailbox on a scheduled basis.
It was pretty easy to write, but usually gets thrown for a loop when "users" start being "helpful" with the email content.
The other thing is that this isn't instantaneous, but is the process really time critical to the second?