Delete Email Attachment - RTF

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

Delete Email Attachment - RTF
Problem to delete an attachment in an email when in Rich Text Format. the TAttachment.Delete method works well in HTML and Plain Text format, but gives an error in RTF. 
Ralf Garbe




Posts: 18
Joined: 2014-11-22
The following code works well when deleting the first attachment in an Outlook MailItem, however only when the format is HTML or Plain. In RichText it fails with the message:
"xxxxx_class_error: the add-in has fired an exception. The operation failed."

The error occures during the a.Delete call.
Any suggestion what goes wrong?

Thanks



var
IDsp: IDispatch;
Mail: outlook2010.MailItem;
attachments: outlook2010.attachments;
a: outlook2010.Attachment;
begin
IDsp := OutlookApp.ActiveInspector.CurrentItem;
if Assigned(IDsp) then begin
IDsp.QueryInterface(IID__MailItem, Mail);
if Assigned(Mail) then begin
attachments := Mail.Attachments;
if attachments.Count > 0 then begin
a := attachments.Item(1);
a.Delete;
end;
end;
end;
end;
Posted 13 May, 2016 14:57:44 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Ralf,

Does this occur on an IMAP folder, PST, Exchange?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 May, 2016 03:43:32 Top
Ralf Garbe




Posts: 18
Joined: 2014-11-22
Hello Andrei,
This is in an Outlook Inspector (Outlook 2010) in an opened Email (for instance a new created email). I use the above procedure to delete attachments in a new created email. Later I want to use that for emails arriving to the Inbox.
Hope this helps,
Best Regards,
Ralf
Posted 16 May, 2016 05:32:44 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Ralf,

Thank you. Outlook receives and stores emails in different store types. My question is about the store type used in your case. If this is a corporate email, then most probably it is Exchange. If you use Gmail or Hotmail, then it may be IMAP folder.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 May, 2016 05:38:55 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
I also believe the other issue you describe in a separate topic may relate to the store type used.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 May, 2016 06:02:52 Top
Ralf Garbe




Posts: 18
Joined: 2014-11-22
Hello Andrei,
thanks for the explanation - the store type is in both cases Exchange.

Best Regards,
Ralf
Posted 16 May, 2016 09:48:09 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Ralf,

Please create a new email in Outlook, attach an email producing the issue, and send the email to the support email address; please find it in {Add-in Express installation folder}\readme.txt. Also, make sure your email contains a link to this topic.

What build of Outlook 2010 are you using?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 May, 2016 10:07:32 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Ralf,

Thank you for sending me that email. The code above works correctly for me on that item. I suggest that you install SP2 and subsequent updates on Office 2010.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 May, 2016 06:45:09 Top
Ralf Garbe




Posts: 18
Joined: 2014-11-22
Hello Andrei,
thanks for the feedback. I just figured out, that the email needs to be saved, before being able to use the delete method for the mail item's attachments. Strange that this is only the case when the email is in RTF format!
Anyhow, I hope this is a stable solution.

Thanks,
Ralf
Posted 18 May, 2016 15:34:53 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Thank you Ralf for sharing your solution with us!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 19 May, 2016 03:18:07 Top