Mail.Delete

Add-in Express™ Support Service
That's what is more important than anything else

Mail.Delete
 
Giancarlo




Posts: 67
Joined: 2016-08-17
I simplify the example, to explain the bug.
As you can see in the figure,

User added an image

I have configured in Outlook 3 imap

When I delete the e-mail,
triggered the event to permanently delete e-mail


procedure TAddInModule.ItemsDeleted(ASender: TObject; const Item: IDispatch);
var
  IMai : _MailItem;
  FMai: TMailItem; //
begin
  IMai:=nil;
  Item.QueryInterface(IID__MailItem, IMai);
  if (Assigned(IMai)) then begin
    FMai := TMailItem.Create(nil);
    FMai.ConnectTo(IMai);
ShowMessage('Now i try to delete this mail ' + FMai.Subject );
        FMai.Delete;
    FreeAndNil(FMai);
    IMai:=nil;
  end;
end;


on the imap trash folder, the delete command does not work

the showmessage() appears,
therefore the event fires
but in Outlook 2010 does not delete

The only solution that could work
is to move the messages that I want to completely eliminate
in functioning box

but I do not know whether it is possible.
I find the trash in this way


    Cestino := OutlookApp.GetNamespace('MAPI').GetDefaultFolder(olFolderDeletedItems);
Posted 21 Sep, 2016 09:48:11 Top
Giancarlo




Posts: 67
Joined: 2016-08-17
how do I find the no imap trash?
Posted 22 Sep, 2016 02:49:26 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Hello Giancarlo,

Namespace.GetDefaultFolder() returns default folders for the default message store. You get default folders for a non-default store using the Store.GetDefaultFolder() method; see https://msdn.microsoft.com/en-us/library/office/ff869924.aspx. The Store object was introduced in Outlook 2010. See also https://msdn.microsoft.com/EN-US/library/office/ff862128.aspx.

Note that the IMAP implementations may differ from Microsoft implementations of Exchange and PST stores. In practice, the difference shows itself in how certain methods or events of the Outlook object model work.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 22 Sep, 2016 07:43:41 Top
Giancarlo




Posts: 67
Joined: 2016-08-17
I can not find the object store.
I also tried searching store, in the unit Outlook2000

I see this example in C#


Outlook.NameSpace ns = null;
Outlook.Stores stores = null;
Outlook.Store store = null;
try
{
    ns = OutlookApp.Session;
    stores = ns.Stores;
...


in Delphi i think:


var
  ns : _NameSpace;
begin
  ns := Self.OutlookApp.GetNamespace('MAPI');
  stores = ???



Have you a Delphi example?
Posted 22 Sep, 2016 10:19:09 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
You need to import the Outlook 2010 type library and use it only if your add-in is loaded in Outlook 2010 or above. See e.g. Using Outlook2010 instead of Outlook2000.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 22 Sep, 2016 10:24:34 Top
Giancarlo




Posts: 67
Joined: 2016-08-17
You get default folders for a non-default store using the Store.GetDefaultFolder() method;


I tried

NameSpace: Outlook2000._NameSpace;
store: Outlook2010._Store;

NameSpace := Self.OutlookApp.GetNamespace('MAPI');
store := (NameSpace as Outlook2010._NameSpace).DefaultStore;

Trash := (store.GetDefaultFolder(olFolderDeletedItems) as Outlook2000.MAPIFolder);


but it return imap trashcan anyway, no store trash
Posted 26 Sep, 2016 03:55:01 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
I assume IMAP is the default store in your profile. If you have other stores in the profile, you can get the Deleted Items folder for these stores by scanning the Namespace.Stores collection.


Andrei Smolin writes:
The Store object was introduced in Outlook 2010.


This isn't correct. The Store object was introduced in Outlook 2007.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Sep, 2016 04:25:22 Top
Giancarlo




Posts: 67
Joined: 2016-08-17
Ok, but my stores are 3 imap and only 1 archive
I need to move the mails into archive trash (no imap)

How can I find what I want?
Posted 26 Sep, 2016 07:27:32 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Scan the stores, identify the store required e.g by DisplayName/FilePath/StoreId. Also, you may be required to use other properties of the Store object to identify the store. If you have no way of identifying the store, consider asking the user to provide this info.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 26 Sep, 2016 07:44:09 Top
Giancarlo




Posts: 67
Joined: 2016-08-17
I found the store trash (it's 2)

However the bug persists in Outlook 2010

i have 4 stores:

1 imap
2 archive
3 imap
4 imap


when i try to move the mail from 1.inbox to 1.trash
ok, but 1.trash.mail is impossible to delete programmatically


when i try to move the mail from 1.inbox to 2.trash
the mail go into 2.trash
and into 1.trash !!!

i can delete 2.trash.mail programmatically
but i cannot delete 1.trash.mail !!!

In short words,
there is a bug in Outlook 2010, which does not allow to delete email from imap trash can
Posted 26 Sep, 2016 08:51:50 Top