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 
Andrei Smolin


Add-in Express team


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

No problem at all. I like helping people. Moreover, I like helping people who WANT to understand.

David Svaiter writes:
BUT, if I can SEND THE FILENAME to that Class


You can access your COM add-in via the following code path:

OutlookApp.COMAddins.Item(strMyComAddinProgId).Object.MyPublicPropertyOrMethod.

1. strMyComAddinProgId - see the ProgId attribute of your add-in module.
2. MyPublicPropertyOrMethod is called via late binding (see System.Type.InvokeMember in MSDN or search through our forums)

See also http://www.add-in-express.com/creating-addins-blog/2010/07/02/standalone-application-addin-communicate/.

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


Could you please clarify this statement? Do you get an exception? I expect Outlook 2013 supports Extended MAPI in the very same way as the other Outlook versions. Or, you are talking about Simple MAPI?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Jul, 2014 06:42:03 Top
David Svaiter




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

Yes, I'm talking about Simple MAPI I guess.
But I had performed the desired action using some OFFICE-like programming, as shown below:

[COLOR=blue]
Dim outlookApp As New Microsoft.Office.Interop.Outlook.Application()
Dim mailItem As Microsoft.Office.Interop.Outlook.MailItem = DirectCast(outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem), Microsoft.Office.Interop.Outlook.MailItem)

Dim myAssembly As Assembly = Assembly.GetExecutingAssembly()
If File.Exists(AttachmentFile) Then
mailItem.Attachments.Add(AttachmentFile)
mailItem.Display(True)
End If


This way I can attach my file into a new message and open it to allow user to choice the desired destination and CC. My problem was solved...

Andrei, that's my MAIN problem and it's now solved. BUT, I really would LOVE if I got a button within Outlook (I had alerady done it with your help before) to perform basically the same action. I mean, I would really like to perform these steps:

1- the user open a new message in Outlook 2013. It writes something.
2- When he ends, he would PRESS MY ADDIN-EXPRESS BUTTON to encode THAT message.
3- my program gets the message at the body, encrypts it, and attach it exactly as performed in my above steps.

Do you see a lot of problems in my wish? I know how to put the AddIn-Express group and buttons, but I couldn't read the original message from the body, discarding completely THAT message and open a new one with the original text already encoded. The final steps I had discovered yet (the above code).

So, I believe my problem is the MIDDLE CODE:
- get the text from the opened message.
- send it to my program.
- discard that original message of the user.

You're very kind person Andrei. Thank YOU very much.
Best regards from Rio.
David
Posted 28 Jul, 2014 20:56:25 Top
David Svaiter




Posts: 12
Joined: 2014-02-02
Ops! Just to complete my idea and avoiding we have that subject in unecessary pieces:

Should be interesting also I have another button to detect an attachment and, once the user press it, I export that attachment to disk and call my application to proceed with decryption.

Thanks Andrei!
See you soon. Bye
Posted 28 Jul, 2014 21:05:43 Top
Andrei Smolin


Add-in Express team


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

If you only talk about plain text, you can use the following steps:
- in the Click even of the button you extract MailItem.Body and send it to your application
- the application encrypts the text and calls a public method defined in the add-in module, the application passes the file name to that method
- the method sets MailItem.Body to an empty string (or some other string) and attaches the specified file to the message

If you need to preserve formatting, you can get the Word.Document (see Inspector.WordEditor) representing the email body, save it to a file (Document.SaveAs()), let your application encrypt the file and inform your add-in about the location of the encrypted file. This approach requires that word is used as the email editor which is always the case in Outlook 2007-2013. In Outlook 2003, can use this approach only if Word is set as the default email editor (see Tools| Options | Mail Format.

You use a variation of the approach above to encrypt an attachment.

Note that using New Microsoft.Office.Interop.Outlook.Application() can lead to Outlook showing security warnings because it creates ab "unsafe" Outlook.Application object. Instead, you need to use the OutlookApp property of the add-in module. This property provides the Outlook.Application object which Outlook supplies to your add-in at startup; Outlook regards this Outlook.application as "safe".

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Jul, 2014 03:36:53 Top
David Svaiter




Posts: 12
Joined: 2014-02-02
Hi Andrei, thanks for reply.

No, we're talking about HTML/RTF/TXT bodies. My approach is get the mail body in ANY format users utilize.

I understand that following the way you recommend I need the Addin Express buttons as default, going to abandon entirely my current approach (we don't attach any button to Outlook via AddIn Express). That's no problem.

I'm involved now with some urgent codes + tutorials to send. I believe in some few days I can try the approach you recommend.

Thank you very much again and if I have troubles to build the routine, I will bother you again (sorry for that!).

Kindest regards Andrei!
Nice to hear you again.
Posted 30 Jul, 2014 13:11:24 Top
Andrei Smolin


Add-in Express team


Posts: 16744
Joined: 2006-05-11
You are welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 31 Jul, 2014 02:37:10 Top