MAPI Outlook object model Mailitem.senton > Mailitem.receivedtime, how is this possible? - vba

I have been trying to figure this out as I am working on a deliverable for which I need to provide metadata for emails. As the title suggests when I am recording this metadata often the MailItem.Senton property will be greater than the MailItem.ReceivedTime property. How is this possible?

This is due to the fact that these values come from different places - the Date MIME header is created by the sender, while the received time is based on the receiving machine time.

Related

Is there a way I can programmatically attach a large file to an outlook message despite it exceeding the server size limit?

A quick note in case you come upon this question hoping for a solution.... there isn't one. Sadly sometimes one has to accept that the right answer to one's question is "You can't do that".
I am hoping there is something I can do here to ensure that attaching a large file to an Outlook.MailItem works exactly the same as doing so manually.
To be precise... when a user composes an email in Outlook and they attach a file that is too large to the email, Outlook will happily attach the file to the email. Instead of simply refusing to do so, it will attach the file and a message will appear in the Inspector:
However....
When coding a similar action you would get access to an Outlook.MailItem and you would invoke the .Add method on its .Attachments object
oMailObject.Attachments.Add("<path to a file that is way too big here>")
The problem is that that action fails. An error is thrown
"The file you're attaching is bigger than the server allows. Try putting the file in a shared location and sending a link instead."
Yes, we can obviously catch the error and then show a message to the user. That's what we're currently doing. It would, however, be nicer if there were a way I can prevent it from raising the error so it would still attach the file to the MailItem, and then when I show the inspector to the user they would see the same thing they would see if they had attached the attachment manually.
Is there an option on the MailItem to prevent it raising an error? Something in the Attachments.Add method? Any suggestions?
The Attachments.Add method doesn't provide anything for that.
You may consider adjusting the maximum size of the attachments in Outlook. Regular mail profiles can be configured using the windows registry keys.
HKEY_CURRENT_USER\Software\Microsoft\Office\<x.0>\Outlook\Preferences
HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\ x.0 \Outlook\Preferences
There you can add a value type: DWORD
Value name: MaximumAttachmentSize
Value data: An integer that specifies the total maximum allowable attachment size. For example, specify 30720 (Decimal) to configure a 30-MB limit. Specify a value of zero (0) if you want to configure no limit for attachments.
Exchange accounts require configuration on the Exchange side, read more about that in the Microsoft Exchange Server email account configuration section.
You can read PR_MAX_SUBMIT_MESSAGE_SIZE MAPI property (DASL name is "http://schemas.microsoft.com/mapi/proptag/0x666D0003") from the store (use Store.PropertyAccessor.GetProperty) - it returns the size in kB - prior to sending the message. This property is Exchange-specific.

get particular Value from InternetMessageHeader in outlook api

On calling /me/messages Outlook API, it returns details of every message including Internet Message Headers, but can we select specific named headers from that. Because while dealing with large amount of data this may reduce some memory... And on performance wise too, it reduces the iterations to search for specific message...
Depending on the Internet header property you want to look at it most get promoted as Extended properties onto the Message so if you use singlevalueextendedproperties definition https://learn.microsoft.com/en-us/graph/api/singlevaluelegacyextendedproperty-post-singlevalueextendedproperties?view=graph-rest-1.0 of that particular property you can get and filter on particular internet headers. You can use a MAPI editor like MFCMapi or OutlookSpy to see what particular extended properties are available on Message.

Print original email when it is undelivered

I'm using MS Office 2016 Desktop App on Windows 10.
I didn't find any success searching online and also contacting MS Outlook Support to find that there is no easy way to achieve it except VBA script.
We send individual mail having an attachment, to a huge bulk of people. (I'm fine with this.)
I want when an email is not sent successfully (because of incorrect email address or other reason), to perform some action on the original email (not the undeliverable mail notice).
Possible action could be printing the mail and its attachments to some other email.
I want this as it is burdensome to print individual emails from around 1000s of emails daily.
MS Outlook rules don't provide the condition for 'when email undelivered' or similar. Can this be achieved with VBA script?
In theory - yes. Firstly, you need to make sure you get the actual NDR and the object type is ReportItem. That shouldn't be a problem if you are sending through Exchange, but if you are sending through POP3/SMTP account or if the NDR is delivered as a regular plain text message from the target server rather than your own Exchange Server, all bets are off.
The various report properties are stored in the recipient table of the NDR items. Unfortunately, ReportItem in OOM does not expose the Recipients collection like it does for MailItem. You can get NDR information from the Body property, but unfortunately OOM has a bug (left unfixed for a few years now) that causes ReportItem,Body to return meaningless garbled text. See Extract text string from undeliverable email body to Excel.
In most cases, you would be able to extract the message id of the original message (that caused in the NDR) from the PR_TRANSPORT_MESSAGE_HEADERS property (take a look at an NDR with OutlookSpy - I am its author - click IMessage button). You can access that property using ReportItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F"). You can then try to extract the In-Reply-To MIME header and use it to search for the original message in the Sent Items folder using Items.Find on the PR_INTERNET_MESSAGE_ID property (DASL name http://schemas.microsoft.com/mapi/proptag/0x1035001F). And here lies another problem - it is possible that the item in the Sent Items folder will not have that property: it is set automatically by Exchange, but the item in teh Sent Items folder in the cached store might not have it because most likely the item in never synchronized (this is due to bandwidth optimization trick by Outlook), so you might have to open the folder in the online mode using the MAPI_NO_CACHE flag, which OOM won't let you use - it is either Extended MAPI (C++ or Delphi) or Redemption (I am also its author - any language). See https://stackoverflow.com/questions/45952523/what-is-the-vba-property-for-server-folder-contains-x-itmes for an example.

Attachments missing on the EWS server for draft email saved via Outlook OfficeJS

I am using the Office.context.mailbox.item.saveAsync method for saving a draft email. This method returns itemId which I later use to make a call to the EWS server to retrieve the email eml content, but the returned eml content is missing some of the attachments.
This is only happening on the Desktop App (Outlook 2013) with cache mode enabled. When using Outlook on the Web it works correctly.
I am using ews-java-api to retrieve the email from the EWS.
Is there a way to know when the email saving is finished?
I can't use the Office.context.mailbox.item.saveAsync.makeEwsRequestAsync because of the 1MB response limitation.
In Cached mode it will take time for the item to sync up to the server. People usually poll until the data they want is there.
Also, they can write a custom property, and check for that property to make sure their item is up to date if necessary.
You can find some details about custom property here: Client Extension Message Object Protocol, Mail App Custom Properties and Mail App Accesses Custom Properties
Is there a way to know when the email saving is finished?
If the following: "Is there a way to know when the email saving is finished?" is your question, than the answer is No. You may try the ugly solution, when you use sub-sequential EWS query with Id you've got from saveAsync in the loop and wait for success. This may take, depend on environment, from a few seconds to like half a minute easily. Not sure if your customers (users) will wait for so long, when add-in finally respond.
You may get more information from the topic: App for Outlook: EWS request failed with item Id returned by item.saveAsync on compose new message
EDIT:
Simple GetItem request can be used as follow ...
<GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ItemShape>
<t:BaseShape>IdOnly</t:BaseShape>
</ItemShape>
<ItemIds><t:ItemId Id="' + itemId + '"/></ItemIds>
</GetItem>
The request should return ChangeKey if item was created on exchange.

Make Time property optional

What do you think about making the "time" property optional in request body to provide more flexibility. This property could be added automatically with current date and time when not present in the request.
It could be useful for SigFox compatibility for example because even if it's possible to add a {time} pattern in message body forwarded by SigFox system, there is no way to modify the format of the datetime generated. Currently the {time} pattern generate a Timestamp and Cumulocity expect an ISO 8601 formatted date time.
Currently I got a "422 - Unprocessable Entity" even if the request is TRANSIENT when I give a Timestamp or no time property when calling Cumulocity. I had the idea to make a TRANSIENT request to store an Event by writing a CEL statement to generate the missing "time" property but it's not possible because the error appears before reaching the event process.
Do you know an other way to do operate?
You can take a look at SmartREST (http://cumulocity.com/guides/reference/smartrest/).
It allows you to create templates for you requests on the server side. Afterwards you just send the values to replace in the template as csv (+ the template id).
It also allows you to let the time value be automatically set by the server.