SmartOutcome
Guest
|
OutlookApp.ActiveInspector returns null when in Inline Response mode in Outlook. What do I need to do to access my current email response here? I need to parse an email and provide template information. Please note that the code works fine when not in Inline Response mode. |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
|
SmartOutcome
Guest
|
Hi Andrei,
I managed to get access to the Explorer.ActiveInlineResponse property and hence the response MailItem object. However, I have a new challenge; when I write into the MailItem.HTMLBody the text gets resent back to the original HTMLBody thereafter. My goal is to append new text to the response while keeping the original email text.
Do you know what is happening here?
Regards |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Hello,
Do you save the item after setting HTMLBody?
Andrei Smolin
Add-in Express Team Leader |
|
SmartOutcome
Guest
|
Hi Andrei
Here is the code snippet:
private void PopulateEmailFields(bool isInspectorNeeded = false)
{
Inspector currInspector = null;
MailItem currMail = null;
Explorer explorer = null;
MailItem response = null;
try
{
if (isInspectorNeeded)
{
explorer = OutlookApp.ActiveExplorer();
response = explorer.GetType().InvokeMember("ActiveInlineResponse",
BindingFlags.GetProperty |
BindingFlags.Instance |
BindingFlags.Public,
null, explorer, null) as MailItem;
if (response == null)
{
return;
}
currInspector = response.GetInspector;
}
else
{
currInspector = OutlookApp.ActiveInspector();
}
if (CheckDetailsAvailable(currInspector))
{
return;
}
currMail = currInspector.CurrentItem as MailItem;
if (currMail == null)
{
return;
}
// add recipients address
currMail.To = foundCustomer.Email;
var strHtml = MergeDetailsIntoEmailBody(FoundTemplate, foundCustomer);
if (string.IsNullOrEmpty(currMail.HTMLBody))
{
currMail.HTMLBody = strHtml;
currMail.Subject = FoundTemplate.Subject;
}
else
{
// we need to append the text from the template and not destroy the current email
var strHtmlBody = currMail.HTMLBody;
var intTagStart = Strings.InStr(1, strHtmlBody, "<body", CompareMethod.Text);
var intTagEnd = Strings.InStr(intTagStart + 5, strHtmlBody, ">");
var strBodyTag = Strings.Mid(strHtmlBody, intTagStart, intTagEnd - intTagStart + 1);
var newBody = Strings.Replace(strHtmlBody, strBodyTag, strBodyTag + strHtml);
currMail.Body = string.Empty;
currMail.HTMLBody = newBody;
currMail.Save();
}
// add any attachments
DoAddAttachments(currMail, FoundTemplate, foundCustomer);
}
catch (Exception ex)
{
var str = ex.Message;
}
finally
{
if (currMail != null) Marshal.ReleaseComObject(currMail);
if (currInspector != null) Marshal.ReleaseComObject(currInspector);
if (explorer != null) Marshal.ReleaseComObject(explorer);
if (response != null) Marshal.ReleaseComObject(response);
}
}
|
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
if (string.IsNullOrEmpty(currMail.HTMLBody))
{
currMail.HTMLBody = strHtml;
...
}
else
{
...
currMail.Body = string.Empty;
currMail.HTMLBody = newBody;
currMail.Save();
}
Note that you don't save the email if the condition is true. And I would comment out the line which sets the Body property.
Andrei Smolin
Add-in Express Team Leader |
|