How Addi attachments to an Outlook item?

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

How Addi attachments to an Outlook item?
 
Giancarlo




Posts: 67
Joined: 2016-08-17
I have 2 TMailItem object (mail 1 and mail 2)

i want copy attachments from mail 1 to mail 2

For mail1 i find this method:


Mail1.Attachments.Item(1).SaveAsFile(filename);


but for mail 2 i find only this method:


Mail2.Attachments.Add( filename, Mail1.Attachments.Item(1).type_,Mail1.Attachments.Item(1).Position, Mail1.Attachments.Item(1).DisplayName );

Mail2.Save();
Mail2.Display();


But I do not see the attachment.
How do I attach a file programmatically?
Posted 01 Sep, 2016 09:45:34 Top
Giancarlo




Posts: 67
Joined: 2016-08-17
Any idea?

i don't understand difference from

FMail: TMailItem;
IMail : IDispatch;

The component support the attachments?
Posted 02 Sep, 2016 05:00:57 Top
Andrei Smolin


Add-in Express team


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

Here's a sample code:

procedure DoSomething(const Item: IDispatch); 
var 
ItemMail: TMailItem; 
begin 
if Item.QueryInterface(IID__MailItem, IMail) = S_OK then 
if Assigned(IMail) then 
begin 
try 
ItemMail := TMailItem.Create(nil); 
ItemMail.ConnectTo(IMail); 
...


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Sep, 2016 05:21:46 Top
Giancarlo




Posts: 67
Joined: 2016-08-17
ok, but how do you attach a file?
Posted 02 Sep, 2016 05:36:45 Top
Andrei Smolin


Add-in Express team


Posts: 14108
Joined: 2006-05-11
Check http://delphi-kb.blogspot.com.by/2011/06/send-email-with-attachment_09.html.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Sep, 2016 05:52:04 Top
Giancarlo




Posts: 67
Joined: 2016-08-17
Ok, but i use your component.
In the event


procedure TAddInModule.adxOutlookAppEvents1ItemLoad(ASender: TObject;
  const Item: IDispatch);
var
  IMail : _MailItem;
  FMail: TMailItem;
begin
//  ShowMessage('ItemLoad');
  IMail:=nil;
  Item.QueryInterface(IID__MailItem, IMail);

  FMail := TMailItem.Create(nil);
  FMail.ConnectTo(IMail);
  ...


i have 2 different object
IMail : _MailItem;
FMail: TMailItem;

i need add attachment into this object
i think FMail.Attachments.Add()

but i don't understand how use it:


function Add(Source: OleVariant; Type_: OleVariant; Position: OleVariant; DisplayName: OleVariant): Attachment; safecall;
Posted 02 Sep, 2016 07:44:52 Top
Andrei Smolin


Add-in Express team


Posts: 14108
Joined: 2006-05-11
The Attachments.Add method is part of the Outlook object model. The method is described at https://msdn.microsoft.com/en-us/library/office/ff869553.aspx. One more example is given at https://msdn.microsoft.com/en-us/library/office/ff862085.aspx.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Sep, 2016 08:18:48 Top