Exchange Transport Agent Bounce MailItem - c#

In our Exchange RoutingAgent, we would like to be able to bounce an email back to the sender in the event of an unexpected exception. We would also like to be able to send the bounce message to some pre-defined admin email too if possible. Is there any way to bounce a message in the OnSubmittedMessage or the OnResolvedMessage events? I am hoping there is some method in the Exchange libraries to easily achieve this, or is there some way to create a new MailItem and send it to the original sender and possibly an admin?

You need to generate a new message to do that there is a sample for this on https://blogs.msdn.microsoft.com/mstehle/2010/03/10/howto-return-to-sender-transport-agent-sample/
You should also be able to use https://msdn.microsoft.com/en-us/library/jj976002(v=exchg.150).aspx
Cheers
Glen

Related

developing outlook add-in, to check if the sent mail item has been replied to

So,
I want to check if the mail I sent to someone, has a reply. In other words, if that person has replied to my mail.
sentboxFolder =
ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentbox);
//So here if i access individual mail and check
Outlook.MailItem mailItem = ( Outlook.MailItem ) sentboxFolder.Items[1];
Now, if i took the PR_LAST_VERB_EXECUTED property of this mail item, what would it return if the mail has a reply sitting somewhere in my inbox and what would it return if noone replied to my mail ?
Also,
I'm not sure if I'd be able to implement this properly, can someone refer me to some examples where PR_LAST_VERB_EXECUTED is used?
Thanks in advance
PR_LAST_VERB_EXECUTED is only set on the messages in your local mailbox. If a recipient replied to the message, PR_LAST_VERB_EXECUTED will be set on a message in his/her mailbox, which you most likely cannot access.
You can try to read PR_CONVERSATION_INDEX property from the message in the sent items folder, then search for a message in the Inbox folder that has PR_CONVERSATION_INDEX starting with the same value.
See the following article on MSDN: http://msdn.microsoft.com/en-us/library/office/cc765583.aspx

How to get back DeliveryNotificationOptions in Message in c#?

I created an application which sends mail but want to know if some of the mail has failed. How could I know that? I try to use code
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
but it just sends through my online mail delivery, I want to see those in application over the Message.Show. Is there any simple way to do that?

Reload IMAP-Message

I have created an IMAP-Server. Now I am searching a way to force the client (in my case an iPhone) to reload a message, because it has changed on the server-side. Does somebody know a way to do this?
The body of a message is not allowed to change in IMAP; the only data item that may be changed for an existing message is the list of flags.
If you want to mimic a change in message body, you effectively have to tell your client that the original message was removed, and a new one created. You achieve the former by sending an EXPUNGE response with the message’s original sequence number, and the latter by sending an EXISTS and/or RECENT response, after which the client would typically issue a FETCH command for the new message.
The IMAP server can't force the IMAP client to do anything.
The closest thing to what you're looking for is IMAP IDLE. With IMAP IDLE, the server can push certain notifications to the client (if the client asked to receive them). The client can then do whatever it wants when it gets those notifications.

Throwing Exception while sending Email to multiple recipients using smtp client

I have an application which uses SmtpClient to send an email. I am trying to send an email to multiple recipients. I have two recipients in my to list e.g "aman#gmail.com,abc#xyz.com". and I am trying to send the email to this list but my application is throwing the exception as below:
Client does not have permission to submit mail to this server. The server response was: 4.7.1 (abc#xyz.com): Relay access denied.
because of this aman#gmail.com is also not able to receive the email.
I need to implement the functionality that even there is an invalid address like abc#xyz.com in the ToList, an email should be sent successfully to aman#gmail.com.
Can anybody please help me in this?
Does this error message come from your own email server, or from that of xyz.com? I'm guessing it's your own server, and that you either need to aunthenticate before sending, or use your own email address for sending (but the latter is kind of a long shot -- "we do not relay" means a server which is neither the sender's or the recipient's refuses to act as a middleman). It is also possible that the mail exchanger for xyz.com is misconfigured (either the MX record in DNS points to the wrong server, or the admin failed to configure it to accept this responsibility - technically basically the same thing) or that your client somehow ends up connecting to the wrong place.
(Not a proper answer but this got too long to fit in a comment.)

SmtpClient get result from server on send

The SmtpClient send method returns void. Is there any way to get the server response? Do I just assume it was successful unless it throws an exception?
The class I'm referring to... http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
To answer your second point, yes, all you can do is assume it's successful - meaning it got the message to the server and the server accepted it, unless you get an exception.
You probably already know the rest of this, but just in case...
From there, the email could get lost and not delivered any number of ways. Your server may accept it and decide not to send it, or accept it and lose power before crashing. It may get blocked by a spam filter along the way, etc.
You can think of an email as being similar to a regular piece of mail in that it passes through several hands between the sender and the recipient. From your code, you can only confirm that it got to the SMTP server you're using to send, which is similar to handing it to a teller at the post office. You don't know (or need to know) how the message is routed from there. it could be by air, ground, or carrier pigeon. You're out of the equation - you don't need to know how it gets sent, just that you trust that they know how to send it. (The same can be said for an email.)
If you need to confirm that the recipient opened it, there are ways of embedding an image in an HTML message on your server and tracking in your logs when that image is accessed, etc. (Google email tracking and email open tracking)
On the other hand...
If the server rejects it, then you do get a server response in a manner of speaking - there should be an error code and a description in the error, which you can use to troubleshoot why it didn't make it, or use error handling to try another route, etc.
You can utilize SendCompleted Event to check that your smtpclient works fine like this:
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.sendcompleted.aspx
But you cannot get confirmation that your message reached recipient because it may stuck in any server/filter in message chain.
You assume that it was successful unless it throws... although success in this case only means that it was accepted by the mail server, anything else is then up to the server...
IF you want a little bit of control you can use SendAsync and hook the SendCompleted event...

Categories