Calling Send method for InLineresponse MailItem on the custom button click event.

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

Calling Send method for InLineresponse MailItem on the custom button click event.
Calling Send method for InLineresponse MailItem on the custom button click event.  
Omkar Deshpande




Posts: 23
Joined: 2019-09-05
Hi Andrei,

We have requirement for which I have added a new button "Send custom". This button is visible on top of the compose window of inlineresponse opening in reading pane.
On this button click event, I want to add few MAPI properties to the mail and want to call Send method on this mail item.
I tried using "ActiveInlineResponse" to get the mailitem but using this mailitem I can not call "Send" method(As per MSDN). Is there any other way to to get mail item on which I can add MAPI properties and also call send method.

Thanks,
Omkar
Posted 08 Apr, 2020 06:04:32 Top
Andrei Smolin


Add-in Express team


Posts: 17370
Joined: 2006-05-11
Hello Omkar,

Omkar Deshpande writes:
On this button click event,


In the Click event of that button, call ADXAddinModule.SendMessage() passing it a unique message; message being an integer >1024. This is all with that event handler. Now you handle the add-in module's OnSendMessage event: filter out your message. When the message is received, you get Explorer.ActiveInlineResponse - this returns an Outlook.MailItem which cannot be sent. You save that mailitem, retrieve its MailItem.EntryId, and close the inline response by calling Explorer.ClearSelection(). Then you use the EntryId previously stored to get the mail item anew: call Namespace.GetItemFromId(). This returns a Mailitem which can be sent: modify it as required and send.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 08 Apr, 2020 07:53:52 Top
Omkar Deshpande




Posts: 23
Joined: 2019-09-05
Hi Andrei,
Thanks for the reply. I tried the way you have mentioned in your reply but I am still getting exception for Send call as this method is not allowed for inlinereply. Please see my code snippet below and let me know if anything is wrong:

private void AddinModule_OnSendMessage(object sender, ADXSendMessageEventArgs e)
{
if (e.Message == 1760)
{
var explorer = TooltipTiker.AddinModule.CurrentInstance.OutlookApp.ActiveExplorer();
var inlineRes = explorer.GetType()
.InvokeMember("ActiveInlineResponse"
, System.Reflection.BindingFlags.GetProperty
| System.Reflection.BindingFlags.Instance
| System.Reflection.BindingFlags.Public
, null
, explorer
, null) as Outlook._MailItem;
if (inlineRes != null)
{
inlineRes.Save();
string entryid = inlineRes.EntryID;
explorer.GetType()
.InvokeMember("ClearSelection"
, System.Reflection.BindingFlags.InvokeMethod
| System.Reflection.BindingFlags.Public
, null
, explorer
, null);
Marshal.ReleaseComObject(inlineRes);
//If I use below 2 commented lines then too I get same exception
// Outlook.NameSpace myNM = TooltipTiker.AddinModule.CurrentInstance.OutlookApp.GetNamespace("MAPI");
// var myMail = myNM.GetItemFromID(entryid) as Outlook._MailItem;
var myMail = TooltipTiker.AddinModule.CurrentInstance.OutlookApp.ActiveExplorer().Session.GetItemFromID(entryid) as Outlook._MailItem;
myMail.Subject = "[Custom]: "+myMail.Subject;
myMail.Send();
}
}
}
Posted 09 Apr, 2020 04:23:45 Top
Andrei Smolin


Add-in Express team


Posts: 17370
Joined: 2006-05-11
Hello Omkar,

I don't see a way to send that mail item. I've tried sending another message once the email is saved and the entryId is obtained. Also, I've tried calling MailItem.Display and call MailItem.Send once the inspector window activates. In all cases, I get the same error message.

I suggest that the user sends the email and your add-in modifies the email in the ItemSend event.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2020 06:36:04 Top
Omkar Deshpande




Posts: 23
Joined: 2019-09-05
Hi Andrei,
Thanks for trying out things for me. Actually it's our requirement to have custom send button. When user clicks on our button, only in that case mail will be modified and then Send method will be called(similar functionality is present in our another COM based add-in where button added in ribbon but it works only for Inspector window). In normal Send button click, we wont be doing anything with the mail.
I will keep searching for the solution. If you get any other idea please let me know.

Thanks,
Omkar
Posted 10 Apr, 2020 05:00:43 Top
Andrei Smolin


Add-in Express team


Posts: 17370
Joined: 2006-05-11
Hello Omkar,

Yes, will let you know if I have an idea.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 13 Apr, 2020 01:33:52 Top
Omkar Deshpande




Posts: 23
Joined: 2019-09-05
I am able to simulate the Send button click for inline response using Automation. Below thread helped to do that. Adding link here so that it may help someone else as well.
https://stackoverflow.com/questions/61142613/using-activeinlineresponse-in-vsto-add-in-send-mailitem-after-modifying-header/61144021#comment108226887_61144021
Posted 16 Apr, 2020 00:24:48 Top
Andrei Smolin


Add-in Express team


Posts: 17370
Joined: 2006-05-11
Wow! Just great!

On the other hand, this is sad: Outlook (and Office) programming is a collection of special cases, workarounds and hacks.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 Apr, 2020 02:08:57 Top
Omkar Deshpande




Posts: 23
Joined: 2019-09-05
Hi Andrei,

I have one more question related to look and feel of my new button. I want this button to have look and feel/theme(and similar UI effects of hover over, click etc.) of the Send and other buttons of ActiveInlineResponse window. Is there any way to achieve that.
Also I want to use icon used for Send button on my new new button, so I used one of your post https://www.add-in-express.com/forum/read.php?FID=5&TID=14403 but what I observed is the images created using this solution looks toned downed and also black color becomes grey etc. Is it expected with this code? Is there any better way to do it?

Thanks,
Omkar
Posted 17 Apr, 2020 04:34:35 Top
Andrei Smolin


Add-in Express team


Posts: 17370
Joined: 2006-05-11
Hello Omkar,

We've checked that code and found a minor issue: it should check if IPictureDisp.Type == 3 before converting it to Bitmap. But in this specific case the check might be omitted; and it is omitted. The issue seemingly belongs to Office. I've googled out this question: https://answers.microsoft.com/en-us/msoffice/forum/all/getimagemso-excel-2016-vba-images-have-no/0dd21519-165e-4061-9e5a-84adcb4dc11f. Note the date on it.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Apr, 2020 05:08:11 Top