Outlook appointment meeting organizer information inconsistent - vsto

I am working on a VSTO add-in for Outlook, written in C# as a WFP application, and am running into an inconsistency in the Outlook provided data for the current selected appointment.
My add-in executes from a button in the appointment dialog. Here are the primary declarations I use to access information from the dialog:
Outlook.Application app = Globals.MyAddInApp.Application;
Outlook.AppointmentItem appt =
app.ActiveInspector().CurrentItem as Outlook.AppointmentItem;
If I open an existing meeting and look at information in appt, the appt.Organizer gives me the name of the meeting organizer as expected. However, if I examine appt.Recipients:
string organizer;
foreach (Outlook.Recipient attendee in appt.Recipients)
{
switch ((Outlook.OlMeetingRecipientType)attendee.Type)
{
case Outlook.OlMeetingRecipientType.olOrganizer:
organizer = attendee.Name;
break;
case Outlook.OlMeetingRecipientType.olRequired:
// ...
break;
case Outlook.OlMeetingRecipientType.olOptional:
// ...
break;
case Outlook.OlMeetingRecipientType.olResource:
// ...
break;
}
}
I'm finding that the meeting organizer has a type of olRequired not type olOrganizer. The organizer string in the above code is not set to the name of the organizer. The appointment dialog "Scheduling Assistant" clearly indicates the organizer, so I'm confused as to how the Type is showing up as olRequired and not olOrganizer.
It would seem odd to me that I can't just use the Type field to determine the roll of an attendee. Do I really have to check the Organizer attribute against the names in the Recipients to detect the organizer in the Recipients list?

Recipient type olOrganizer (0) is not used at all. You can only have To / CC / BCC recipients (mapped to olRequired / olOptional / olResource for appointments).
On the MAPI level, the organizer is marked by the recipOrganizer bit (2) in the PR_RECIPIENT_FLAGS set on the recipient. You can see that property in OutlookSpy (I am its author) - select the appointment, click IMessage button, go to the GetRecipientTable tab, select the organizer, select the PR_RECIPIENT_FLAGS property, right click, "View Property".

I've also faced this issue and was investigating.
This looks definitely like a bug in Outlook to me. I have opened a uservoice (for this one and another). Let's see if Microsoft will fix it.
https://outlook.uservoice.com/forums/322590-outlook-for-windows-desktop-application/suggestions/42151741-outlook-vba-wrong-recipient-type-for-organizer-olm

Related

Outlook VBA - can view email Source Code?

In MS Outlook, I want to loop through each selected email, and for each email, view the source code and check if the source file (as in txt format) contains a certain string "XX". Since using view source code can display the email content into html format and I would like to trace some format which with issues in the text.
Currently, I am doing manually by opening the mail, right click > View source > Ctrl+F to find the string I am looking for.
Is there a view to use VBA to do the action of "view source" in the email?
Dim individualItem As Object
For Each individualItem In Application.ActiveExplorer.Selection
'View Source Code of the email
'Find "XX" in the email body content
If Instr(individualItem.body, "XX") = 1 Then
Msgbox ("Find string!")
End if
Next Message
Thanks.
You are almost right, I see two issues:
1.) There are two distinct properties Body (only text) and HTMLBody.
2.) Instr returns the position of the search token. It can be any positive number if the token is found.
So try:
If Instr(individualItem.HTMLBody, "XX") <> 0 Then
By "source" do you mean the MIME headers of the message? They are stored in the PR_TRANSPORT_MESSAGE_HEADERS property - take a look at the message with OutlookSpy (I am its author - click IMessage button). You can reads that property using MailItem.PropertyAccessor.GetProperty. The DASL name of the PR_TRANSPORT_MESSAGE_HEADERS property "http://schemas.microsoft.com/mapi/proptag/0x007D001F".
Note that full MIME source of a message is never stored by Outlook - MIME is not native Outlook format.

Send calendar item properties from Acces form to Outlook agenda

My script in Access-vba works (I can send from an Access form a calendar item to Outlook). But now I want to send some poperties (such as subject and location of the appointment) to the agenda in Outlook and then I get an error (see image attached). For subject I want to use some text from my current form (Me.Monitor_account) but that does not work. See the image attached. If I use: .Subject = "test" then it works. But I dont see the difference between the two.
.Subject = (Me![MonitorAccount]) 'worked!

outlook vba code to display pictures in email

By default, my MS Outlook 2013 is set NOT to download images in received HTML e-mail messages. I would like to keep this setting.
There are some senders whose emails are handled by my Outlook VBA code...and filed into specific folders (rather than the INBOX). I do not use the in-built RULES.
These are known senders...and I would like to have the pictures in the emails from these SELECT KNOWN senders downloaded and displayed. I could do this manually for each email... by right clicking etc... but that is a pain... when there are many such emails.
I am unable to figure out the few lines of code (one line ?) required to download / enable display of images / pictures in the email. Something like... MailItem.Display (which does not work... it only displays the mail in an independent window)... or MailItem.DisplayImages (that is not a known method!).
I would include this one line (or lines) in the routine which handles emails from some known senders....so that their emails always have images / pictures downloaded and displayed.
Thanks.
You would need to set the PidTagBlockStatus property - see http://msdn.microsoft.com/en-us/library/ee219242(v=exchg.80).aspx.
Note that while you can read/write that property using MailItem.PropertyAccessor.SetProperty, you will not be able to calculate its value correctly - Outlook Object Model rounds off the value of the message delivery time, and you would need the raw Extended MAPI value (accessible in C++ or Delphi only) as the FileTime structure.
If using Redemption (I am its author) is an option, it exposes the RDOMail.DownloadPictures property. Something like the following should do the job (VB script):
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Item = Session.GetRDOObjectFromOutlookObject(YourOutlookItem)
Item.DownloadPictures = true
Item.Save
The Outlook object model doesn't provide any property or method for that.

Accessing User Defined Fields in Outlook

So, I have a custom email form/message like below and I want to access the "Doc Title:" field value to insert it into the body of the email.
I currently have this code;
Function Item_Send()
Item.Body = Item.Body + UserProperties.Find("TextBox1").Text
End Function
And I've tried multiple variations of this, such as Item.UserProperties.Find(...).Value, Find(...).Value by itself, UserProperties.Find("TextBox1", false).Text, etc.
Research;
CodeProject
MSDN Find Method Documentation
Microsoft Support - How to create an email message form
Microsoft Support - FAQ about custom outlook forms
Microsfot Support - Working with User Defined Fields
I just can't seem to find a solution.
The posted code returns Object requred: 'UserProperties.Find(...)'
If I add in false to the parameters I get; Object doesn't support this property of method: 'UserProperties.Find'
Find by itself gives me Type mismatch: 'Find'
And that's all the error messages I can get to come up. Any help would be greatly appreciated. (I'm using the Script Editor button to write the above code, not the Visual Basic button).
You never check that UserProperties.Find returns null. Change the problematic line to
set prop = Item.UserProperties.Find("TextBox1")
if Not (prop Is Nothing) Then
Item.Body = Item.Body + prop.Value
End If
Also make sure the property name is really "TextBox1", that sounds like a control name. Have a look at the item with OutlookSpy (I am its author): click Item button, select the UserProperties property, click browse, go to the IEnumVariant tab, double click on the property.
You can also click the IMessage button to see the raw MAPI properties.

Programatically Show/Hide the FROM field in Outlook using c#

Is there any way to show/hide the FROM field in Outlook programatically?
The reason I want to do this, is because some code i've wrote so far successfully sets the FROM field.
However, after the first time it is ran, the FROM field is set, but the UI doesn't reflect this change.
Hiding and then re-showing the FROM field forces the UI to update. Ideally I want to find a way to do this in both 2007 and 2010.
If it isn't possible to hide and re-show the FROM field programatically is there any other way to force the UI to refresh?
//Get the explorer window and the currently selected item
Explorer activeExplorer = this.Application.ActiveExplorer();
MailItem origMsg = activeExplorer.Selection[1];
Recipients origRecipients = origMsg.Recipients;
if (origRecipients.Count == 1)
{
AddressEntry address = origRecipients[1].AddressEntry;
currentMsg.Sender = address;
//currentMsg.SentOnBehalfOfName = origRecipients[1].Name; currentMsg.send
}