Get the failure reason from a mail in outlook - email

I am doing some automation on outlook mail box, previously it was lotus notes.So i am looking for equivalent properties in outlook. The lotus notes mail items has a item named FAILUREREASON which has the details about why the email is failed such as delivery failure reason etc. This item will be available when the mail is a delivery failure email. So when i loop through mails in inbox i can recognize which mail is a delivery failure email in inbox and which is actual required mail to be processed. But in outlook MailItem object i didn't find any option to get it. I searched for any solutuion but not able to find any. We can search subject for words such as 'failure' but it's not good approach. Can anyone know the property that i need to look or any other approach for the same.

Standard bounce or undeliverable emails are received in Outlook as special items using the "REPORT.IPM.Note.NDR" message class and are available as a ReportItem object in the Outlook Object Model. You can also read the mail header information via the PR_TRANSPORT_MESSAGE_HEADERS_W MAPI property on any kind of email.
One way of retrieving the value is by using PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F")

ReportItem object in the Outlook Object Model (not related to the MailItem object) exposes NDR information through the ReportItem.Body property. On the Extended MAPI level (C++ or Delphi only) the properties are stored in the recipient table - you can see the data in OutlookSpy (I am its author) - click IMessage button, go to the GetRecipientTable tab:
For the MailItem objects, you can access that information using Recipient.PropetyAccessor.GetProperty method, but ReportItem object does not expose the Recipients collection (unlike the MailItem object). In theory, you can change the MessageClass property to "IPM.Note", remember the value of the EntryID property, save the NDR, release the original, reopen the item as a regular MailItem object by calling Namespace.GetItemFromID, and then read the data from the recipient table. But that means modifying the original NDR (its modification time will change etc.).
If using Redemption is an option (I am its author), its RDOReportItem object (derived from the RDOMail object) exposes the Recipients collection. You can reopen Outlook's NDR in Redemption by creating an instance of the RDOSession object and calling RDOSession.GetRDOObjectFromOutlookObject method. The recipient properties will be accessible using RDORecipient.Fields[].

Related

Get MessageID of a sent mail in Outlook

I'm currently writing on an Outlook VSTO AddIn. Using this AddIn, I would like to keep track of E-Mail conversations and be able to uniquely identify mail messages. We are using Exchange as MTA.
For all the mails in the Inbox (and many other folders) I can use the Message ID from the mail's header to do the matching, but mails lying in the "Sent Items" folder do not have a Message ID set.
Is there a way to get the Message IDs from those mails?
(I guess that the mails do not have a header, as they are placed in the folder before being sent; but after sending the mail, the MTA gives a message with status code 250 which contains the Message ID.) Does Outlook know about or somehow save the MessageID? How can Outlook keep track of conversations, if it doesn't know the MessageID?
Is there another way to identify a mail?
First let us clarify why do you mean by
Is there another way to identify a mail
Actually you can duplicate an email then, they will have the same MessageID but different ItemId. If you have multiple recipients: toms#gmail.com, toms#an.exchange.mailbox.com, toms2#an.exchange.mailbox.com they will have the same MessageID (aka InternetMessageId) even the first one is not even Exchange. For the two others, there are two different messages within the same Exchange server. The have differents ItemID(aka EntryId).
Conclusion, the MessageID identifies the mail from its content and is set by the mailserver sending the email. To my knowledge there is no alternative (except creating your own "digest") from the immutable properties of an email. Keep also in mind that 'ItemId' changes when you move an email from a folder to another. See
For a VSTO add-in you can retrieve the MessageID aka InternetMessageId using Redemption.
The other alternative is to ask the ExchangeServer using MAPI or EWS.
In all cases there will be a 'server call' and it cannot be retrieve directly after sending because this property is set by Exchange Mail server.

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

Can I replace Sitecore Email Sending Service?

By default smtp server can be configed in Sitecore web.config. However is it possible to hijack the whole email sending part to use a different method instead of a smtp server? Is there some kind of pipeline?
For example, I want to use another web service to send all emails, or I want to save all of them into a database instead of actually sending them?
Also a different question would be, does content delivery instance need to send emails by default? I would assume all out-of-box email sending are from content authoring instance right?
And from my understanding, there's only workflows in Sitecore need to send emails and it can be customized by changing the email action. (Assume no Email Campaign Modules, no Webform for Markets module and etc.)
Any insight would be great help, thanks!
--------------Update---------------------29/09/2015--------------
I have got my answers, thanks everyone.
Basically I shouldn't need to working about the smtp server on CDS instances, and all email sending can be controlled by pipelines on CAS instances.
However when I checked the source code, there's only one place "Reminder" which uses the smtp server to send emails directly. So if this function is important to you, you should consider update this function.
Yes absolutely.
At runtime when you are defining the SMTPClient you can set the properties for the server by the following code
SmtpClient client=new SmtpClient("Host");
client.Credentials=new NetworkCredential("username", "password");
MailMessage mailMessage = new MailMessage();
mailMessage.from="sender#gmail.com";
mailMessage.To.Add("recipient#gmail.com");
mailMessage.body="body";
mailMessage.subject="subject";
client.Send(mailMessage);
What you can do, instead of having the values hardcoded in the code you can retrieve the values from Sitecore Items and use those, this will allow greater control for Content Editors and even use different SMTP Server in different parts of functionality.
Item emailItem = Sitecore.Context.Database.GetItem("Id of Item");
string from = emailItem["From"];
string to = emailItem["To"];
string server = emailItem["Mail server"];
string subject = emailItem["Subject"];
string message = emailItem["Message"];
There is a SendEmail pipeline apart of Sitecore's EXM aka ECM which you can override if you take the EXM route. It has two processors FillEmail and SendEmail which you can utilise or remove and add your own processor for actually sending the message.
It is possible to save the emails to a database, or rather the content, instead of sending them. This can be achieved by custom code in Sitecore or Webforms for Marketers which has Save Actions for Sending Emails or Saving to a Database and its really simple to configure.
As you said there is no need to send emails on every occasion its more about determining what you are trying to achieve and if Sending Emails, Saving to Database etc is more relevant. The great thing about Sitecore is you can create Items programmatically and store the information there, save you worrying about creating database tables, managing ConnectionStrings, setting up EntityFramework etc.
Here is a simple blog on creating Sitecore Items Programmatically.
Sitecore Workflow sending Emails is optional and can be removed by deleting the Send Email CommandAction Item from beneath the WorkflowState Item and then publish.
The easiest way to intercept all emails is to configure Sitecore to send all emails to the locally hosted SMTP server (127.0.0.1) and then grab them from there using your custom code.
There is a lot of free SMTP servers, just make sure you test them with high volume of emails before moving to production.

How to get all the email addresses that belongs to the sender's group, in outlook 2010, using powershell scripts

I would like to get all the email addresses that belongs to the sender's group, in outlook 2010 professional, using PowerShell.
For example, person A sends me an e-mail, and A belongs to group X. So I would like to use PowerShell to get all the email addresses that belongs to group X.
I was reading outlook Api documentations but found nothing related to that. Any help would be really appreciated.
Thanks,
Ruijie
Do you mean the "Member of" tab in the Exchange user properties dialog? Retrieve AddressEntry object from MailItem.Sender, then use AddressEntry.GetExchnageUser().GetMemberOfList function (be prepared to handle null and/or errors). Loop through all items in the returned AddressEntries list.

Tracking response to an email

I need to send via agent some emails and I want to track the responses to these emails with an agent on the mailbox of the user.
Is there any field I can use to set/read to achieve this?
The flow:
1) the user create a document in a database (on the web);
2) the WebQuerySave agent creates the email, saves it in a mail-in db and sends it to the recipient;
3) the recipent sends a reply;
4) an agent on the mail-in db should read this reply and write some data back to the original document made by the user... and that's what I'm trying to do and I can't rely on the subject because it's all on the final users hands...
Is there any way I can do it?
Thanks for any advice.
Since you are dealing with outside recipients and can't control the software that they use or how they use it, it is going to be difficult to handle 100% of cases. You are going to need to build a mechanism into your solution for marking exception cases where automatic matching fails so that someone can handle them manually.
That said, you can set a special flag in your outgoing mail. Assuming that your webQuerySave agent uses mailDoc as the object name for the NotesDocument that it is going to mail, just do this:
mailDoc.ReplaceItemValue("mySpecialFlag",evaluate("#unique"))
In order to get this value to go out in the email, you are going to have to make sure that the Domino server that performs the conversion from Notes format to SMTP is configured with the outbound MIME option to "send Notes private items", which is described here. This will create a custom x-notes-item header in the outbound message, and as long as the receiving email system preserves it and copies it into the end-user's reply message, that header will be received back by Domino and converted into an ordinary NotesItem that your agent in the mail-in database can look for. I think that most ordinary mail software will preserve this header for you in replies, but you will need to be handle cases where the haeder doesn't come back either because the outside mail system's software doesn't preserve it or because the user creates a new message and copies the old one into it instead of doing a normal reply.