Outlook MAPI-Moving Email to Outbox Lands it as Draft - outlook

I write an outlook add-in and I am new to it, so please elaborate.
When I am offline and attempt to send an MailItem, the MailItem is moved to outbox. However, I noticed (as per screenshot below), that it has "draft" icon and no date.
As a result, when I get online, it will never get sent.
How do I move it to outbox folder but have it land there not as a draft?
I move it lilke this:
(myItem as MailItem).Move(myOutboxFolder);

Why do you expect a message moved to the Outbox folder to become sent? You need to create it in the sent state (it cannot be changed later), and that means you can only create a PostItem, not MailItem.
To send a message, you need to call MailItem.Send. Moving it to the Outbox will not sent it - Outbox is just an eye candy.

Related

Outlook API, Message Moved to "Sent Items" still beign marked as "[Draft]"

I'm working on an Outlook Add-in, using office.js, where users can send secure emails using backend service.
In compose mode, when the user sends the email, using the add-in of course, the add-in will then move the message to "Sent Items" folder using the Outlook API /message/{id}/move and everything goes OK with the exception that the message in question still being marked as "Draft" by Outlook which is really annoying and does confuse the user who just sent the email by telling him that "this message hasn't been sent"
I searched through the API to see if there is a way to mark an email as "SENT" in order to prevent Outlook from showing this RED hint but with no luck so far!
So, My Question Is: Is there any way to overcome this misleading msg by marking the email as it was sent by Outlook?
Thanks in advance.
Finally, I was able to achieve a perfect solution for this challenge.
Based on:
#BrianClink's comment
This answer (Which uses Graph API but Outlook REST API): Microsoft Graph API mail office 365: Is any option create inbox message NOT as Draft?
The approach/steps I followed to mark a mailItem as "SENT" (and not shown as 'draft') and put it in "SentItems" Folder are as follow:
First, Save the mailItem as "draft" using Office.context.mailbox.item.currentMail.saveAsync then retrieve its ID
Clone this draft mailItem properties eg: 'Sender', 'Subject', 'Body', 'ToRecipients'..etc so you get an exact copy of it.
With the newly cloned mailItem, add '[SingleValueExtendedProperties]' property with this value :
[
{
PropertyId: 'Integer 0x0E07',
Value: '1'
}
];
Serialize the new item as JSON and POST it to "sentitems" folder as follows:
xhr.open('POST', restHost + '/v2.0/me/MailFolders/sentitems/messages/');
xhr.send(clonedEmailJson);
On success, with xhr.status=201 [created], Remove the draft mailitem using a [DELETE] request
And you will end up having a new mail item created in your "sentItems" folder which appears as it was sent by Outlook :)
This was a very helpful solution to me because my users are using my add-in to send secure emails (using 3rd party API) and NOT Outlook, So, I wanted them to have the same UX/feeling as when they use Outlook.
Note:
Although the solution worked for me perfectly, it came with a price!
On slow internet connections or in case emails containing large attachments, the process can be remarkably slow, because the addin will first save the draft to the remote Exchange Server, get its ID, then duplicate it and send it again to the server, then remove the draft-ed one.

A MailItem saved in the ItemSend Event is saved as draft

I'm developing an Outlook add-in that allows the user to save an email to the filesystem just after it's been sent.
To achieve this, I intercept the Application.ItemSend event, and inside my handler I call MailItem.SaveAs(...). It works, basically.
The problem I'm facing is that, when I open the file saved, the email is in draft state. I mean, the recipients, subject and message body can be modified, and the email can be resent. I want the email to be in "sent" state, i.e. not modifiable.
It looks like Outlook API does not provide any event dispatched after the email is sent. Only before, and this is my pain.
Do you have any idea to perform this?
Thanks a lot for your help!
Nico
the earliest you can save the message in the sent state and with the sender properties populated is when Items.ItemAdd event fires on the Sent Items folder.

GMail API: Trashing first email seems to remove entire thread

I'm using the GMail API in Go(lang). After each email arrives I am 'inserting' (not sending an email onto the same thread (with stats about how many times you have communicated with this person etc etc...
What I want to end up with is the original incoming email trashed, and the inserted email first in the thread. The content of the original email is appended to the inserted email.
All works, except that when I trash the email with the ID of the original email, the entire thread disappears.
Is this because the appended email is inserted and not 'sent' to the thread? I wouldn't have thought so because it gets given a real messageID, so is it because I am trashing the first email in a thread, and that therefore trashes the whole thread?
I thought trashing should just trash the message, regardless of its 'ownership' of the thread.
Thanks
You may refer with this post although the issue here is to retrieve the specific email within a thread. It stated that it is not currently possible because it is part of the email's body content and you're specifying the ID of the message to trash. You can only trash other messages within a thread, but not the primary message since the messageId and the threadId of the first email is the same. Yes, using the Gmail App it's working, but I think it is not yet supported using the API. You can file a feature request for this.

Create text/calendar type email that triggers accept/reject/ignore options

I can programmatically create an email with an .ics file attached. The email gets sent, the recipient clicks the .ics attachment to add it to their calendar. This is easily done.
I want to try and make Outlook behave a little different. When the user previews the message it detects that its calendar type and throws a prompt asking the user to take some action. This action decides if it gets pushed into the calendar. In a perfect world to have accept/reject/ignore options would be super sweet. Is it possible to construct/send and email in such a way that Outlook can treat it different from a standard email? E.G perhaps altering the type (CONTENT-TYPE:text/calendar)?
Note - I have seen a solution where the body contains a link to the .ics file informing the user about the calendar invite details. It then has a click here to Accept. This is nice because the .ics file does not have to be attached.
I am workign in VBScript/VBS world although Im not sure this is all that important. Has anybody done this is any sense. Is it even possible?
edited:
I ended up using the EASendMail component located here it has an autoCalendar property which works really well. It embeds the .ics file as a text/calendar and send the message as a text/calendar. The outcome is perfect, just like it was actually sent from the outlook. It previews with with the action buttons and even loads the meeting in Outlook at tentative waiting for action
Your email needs to follow a proper MIME structure for it to be recognized as an invitation. See Multipart email with text and calendar: Outlook doesn't recognize ics

meeting properties are not preserved by outlook

In a Outlook addin I want to set PS_INTERNET_HEADERS properties on outgoing emails/meeting requests. I can see that for meetings those properties are not preserved when I open the incoming meeting (I send it to myself) - the email header for my property does not exist and I cannot see the property in OutlookSpy. for regular emails (not meetings) properties are preserved fine.
I can also reproduce this behavior with OutlookSpy - I create a new meeting, in OutlookSpy I add a PS_INTERNET_HEADERS named property, and send the meeting to myself. when I open the incoming meeting the property is gone. (it also does not appear when I open the meeting from the SentItems)
When and how do you set the properties? Keep in mind that AppointmentItem is never sent. When you call AppointmentItem.Send, a new MeetingItem object is created and sent. You can only access it in the Application.ItemSend event handler.

Resources