Using AddIn Express to Attach File and Open new Message

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

Using AddIn Express to Attach File and Open new Message
Automating attachment file into a new message through AddIn Express 
David Svaiter




Posts: 12
Joined: 2014-02-02
Hello,

In Office 2003-2007-2010 I can utilize MAPI to open NEW MESSAGE form with an attachment already within it.

But I guess in Outlook 2013 (Office offline version, not Outllok 2013 365) it seems not be possible. I don't need button in the Outlook application, or in other words, it is not mandatory. I only need to open a new mail message with an attachment built by my application.

I have the full version of AddIn Express for Outlook.
Is it possible to perform it anyway?

Kindest regards,
David
Posted 24 Jul, 2014 17:59:29 Top
Andrei Smolin


Add-in Express team


Posts: 17449
Joined: 2006-05-11
Hello David,

David Svaiter writes:
But I guess in Outlook 2013 (Office offline version, not Outllok 2013 365) it seems not be possible.


I wonder why you think so.

Create an Outlook add-in project, put an Outlook Events component onto the module. Handle the NewInspector event of the ADXOutlookAppEvents component and also the AddinInitialize and AddinStartupComplete events of the the add-in module:

private void adxOutlookEvents_NewInspector(object sender, object inspector, string folderName) {
    System.Diagnostics.Debug.WriteLine("!!! adxOutlookEvents_NewInspector. start");
    object currentItem = (inspector as Outlook._Inspector).CurrentItem;
    if (itemEvents.IsConnected) {
        System.Diagnostics.Debug.WriteLine("!!! adxOutlookEvents_NewInspector. itemEvents.IsConnected");
        itemEvents.RemoveConnection();
    }
    if (currentItem is Outlook._MailItem) {
        System.Diagnostics.Debug.WriteLine("!!! adxOutlookEvents_NewInspector. currentItem is Outlook._MailItem");
        itemEvents.ConnectTo(currentItem, true);
    }
    if (!itemEvents.IsConnected) {
        System.Diagnostics.Debug.WriteLine("!!! adxOutlookEvents_NewInspector. !itemEvents.IsConnected");
        // If we've connected to events of currentItem, we must not release it
        Marshal.ReleaseComObject(currentItem);
    }
    System.Diagnostics.Debug.WriteLine("!!! adxOutlookEvents_NewInspector. finish");
}

OutlookItemEventsClass1 itemEvents = null;
private void AddinModule_AddinInitialize(object sender, EventArgs e) {
    System.Diagnostics.Debug.WriteLine("!!! AddinModule_AddinInitialize");
    itemEvents = new OutlookItemEventsClass1(this);
}

private void AddinModule_AddinStartupComplete(object sender, EventArgs e) {
    if (itemEvents.IsConnected) {
        itemEvents.RemoveConnection();
    }
}


Add an Outlook Items (not Items!) Events class to your add-in project, see the Add New Item dialog. This class is mentioned as OutlookItemEventsClass1 in the code above. Modify the ProcessOpen method of the class as follows:

using Outlook = Microsoft.Office.Interop.Outlook;
using System.Runtime.InteropServices;
...
public override void ProcessOpen(AddinExpress.MSO.ADXCancelEventArgs e) {
    System.Diagnostics.Debug.WriteLine("!!! ProcessOpen");
    if (this.ItemObj is Outlook._MailItem) {
        System.Diagnostics.Debug.WriteLine("!!! ProcessOpen. this.ItemObj is Outlook._MailItem");
        Outlook._MailItem mail = this.ItemObj as Outlook._MailItem;
        if (mail.EntryID == null || mail.EntryID == "") {
            System.Diagnostics.Debug.WriteLine("!!! ProcessOpen. mail.EntryID == null || mail.EntryID == ''");
            Outlook.Attachments atts = mail.Attachments;
            Outlook.Attachment att = atts.Add(@"D:	est.pdf");
            Marshal.ReleaseComObject(att); att = null;
            Marshal.ReleaseComObject(atts); atts = null;
        }
    }
}


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Jul, 2014 04:27:24 Top
David Svaiter




Posts: 12
Joined: 2014-02-02
Good morning Andrei.

Thank you for your prompt response.
I'll try what you're recommending.

As soon as possible I'll be back with the status of my try.

Kindest regards,
David.
Posted 25 Jul, 2014 07:40:07 Top
David Svaiter




Posts: 12
Joined: 2014-02-02
Dear Andrei,

I'm sorry but I believe I'm doing the right things.

- I opened a new project and created a new AddInModule.vb.
- I opened the AddInModule.vb[Design] and put "adxOutlookEvents".
- When I paste your code into the CODE section of that module, the properties/methods as .IsConnected, .ConnectTo appear in RED, like being not recognized.

I went to the manual but I don't see where exactly I made something wrong (or I didn't make any required thing).
Could you PLEASE help me again?
Look the code section as appeared:



User added an image
Posted 25 Jul, 2014 08:30:38 Top
David Svaiter




Posts: 12
Joined: 2014-02-02
Just for additional info:

I I select my project, and try to add an "Add-In Express Items - Outlook - Outlook Items Event Class" (named by default as "OutlookItemsEventsClass1.vb" ), I get the following error message:

NOT IMPLEMENTED (Exception from HRESULT: 0x80004001 (E_NOTIMPL))
Posted 25 Jul, 2014 08:37:08 Top
Andrei Smolin


Add-in Express team


Posts: 17449
Joined: 2006-05-11
David,

My bad.

The second step should read as follows:

Add an Outlook Item (not Items!) Events ...

The file should be named OutlookItemEventsClass1, not OutlookItemsEventsClass1.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Jul, 2014 08:40:20 Top
David Svaiter




Posts: 12
Joined: 2014-02-02
Hi Andrei, no problem at all. I'm really appreciating your efforts to help me.
I'm going to try your advice.
Please, hold on some minutes...

Regards from Rio de Janeiro.
Posted 25 Jul, 2014 09:02:05 Top
David Svaiter




Posts: 12
Joined: 2014-02-02
Andrei,

The project had compiled normally as you recommended above. Visual Studio built a DLL file.
Please, could you help me in the following questions?

1- Can I merge the source project to my solution or I just have to reference the created DLL file?
2- Should the LOADER folder exists below my application main folder, I mean, must I have to include that LOADER folder under my application's main folder?
3- Must I have to reference ALSO the LOADER DLL files or they will be reference at runtime?

Just for my better understanding:
I would like to add different named files when the user press a button within my application. These files (one at a time) will be created with different names at different times since they are encrypted text file sent from a company to another one. I have the feeling the DLL just add a fixed-name file EVERYTIME a new message is created in Outlook. Am I wrong in my wondering?

Thank you VERY much for the whole patience with my questions and efforts to help me.
David
Posted 25 Jul, 2014 09:20:34 Top
Andrei Smolin


Add-in Express team


Posts: 17449
Joined: 2006-05-11
David,

#1. If you have an existing add-in project, then you need to copy the code above to that project.
#2-#3. A newly-created Add-in Express project includes the Loader folder. The folder contains three VERY important files: adxloader.dll, adxloader64.dll and adxloader.dll.manifest. I suggest that you leave the folder intact. Please read more abot the loader in sections "Add-in Express Loader" and "Add-in Express Loader Manifest" in the PDF file in the folder {Add-in Express}\Docs on your development PC.

David Svaiter writes:
I have the feeling the DLL just add a fixed-name file EVERYTIME a new message is created in Outlook. Am I wrong in my wondering?


That's correct. This is a sample that you need to adapt to your requirements.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Jul, 2014 09:35:39 Top
David Svaiter




Posts: 12
Joined: 2014-02-02
Andrei, thank you for the whole help.
I'll read the suggested paragraph in PDF file, no problem at all.

BUT my doubt remains the same.
I need to provide to my users a kind of procedure that:

1- When the user finish some processing within my application, he PRESS a button to SEND INFO.
2- At this point, my app encrypts the info and saves it into hard-disk in encrypted mode.
3- At next, I call MAPI and:
3.1 - Open a NEW message in Outlook.
3.2 - Attach the encrypted file.
3.3 - And the user can write some extra info in the message body or somehing else.

The entire step 3 I can perform normally utilizing MAPI, except in Outlook 2013 - it does not respond to MAPI processing.

So, in your sample I can't see a way to perform these steps. I don't want to attach the same file everytime user open a new message (since the original/encrypted info is not already done!). BUT, if I can SEND THE FILENAME to that Class I can manage the PROCESS CLOSE/PROCESS SEND to delete the file, avoiding that a new message re-attach the same info.

Do you see another way to perform these steps OR I have ONLY the recommended procedures to do so?
And can I pass the attachment filename as a public variable or you see another better way?

I'm sorry if I'm being inconvenient to you. But your help is VERY important to me.
Thank you very much again.
Kindest regards,
David
Posted 25 Jul, 2014 09:57:56 Top