I am encountering a strange issue in my outlook addin application. It is being run on Outlook 2010.
I enter an email address e.g: abc#foo.com into the "TO..." box in the email. I have the following code to get the recipients:
var dynamicMailItem = (dynamic) mailItem;
var recipients = (string)dynamicMailItem.To;
However, recipients returns an empty string! But when I evaluate dynamicMailItem.To in the immediate window, all of a sudden, the value is returned. How can I force consistent behavior?
Thanks!
You're improperly casting dynamicMailItem.To, which is why the variable recipients contains nothing after the fact.
The code you posted isn't valid - there's one extra close bracket. It must not be an exact copy paste from your add-in, or you would see a compile error. Can you post exactly the code you have that assigns the value of var recipients?
Related
I have developed a VSTO plug-in. We have hooked the ItemSend event in our code. When I try to send mail, I am trying to remove all attachments before sending it. However mail is still having all attachments which were removed. I can see them in send folder as well as in inbox.
Strange thing is that when I print count for number of attachments, it is giving 0. But when I print mime using MAPI object and APIs, it is still showing attachment there. It seems that MailItem object of OOM is not in synch with MAPI object.
Is there any way to enforce this synchronization.
I have written following code --
int numOfAttachments = mailItem.Attachments.Count;
for (int index = numOfAttachments; index > 0; --index)
{
Attachment attachment = mailItem.Attachments[index];
attachment.Delete();
Marshal.ReleaseComObject(attachment);
}
PrintInfo("Attachment count - " +
mailItem.Attachments.Count.ToString());
mailItem.Save();
string mimeSource = MimeParser.GetMimeSource(mailItem);
File.WriteAllText("C:\\Test\\Mime2.txt", mimeSource);
Marshal.ReleaseComObject(mailItem);
return;
I guess the Attachments.Remove method leads to same results, right?
First of all, I'd recommend releasing all underlying COM objects instantly. For example:
int numOfAttachments = mailItem.Attachments.Count;
The Attachments property returns an instance of the Attachments collection which is left alive. You need to release only objects you get from the Outlook object model via properties and methods. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about this in the Systematically Releasing Objects article in MSDN.
Finally, the ItemSend event handler allows to cancel the default action by setting the cancel parameter to true. So, you could do any modifications and send submit the mail item anew.
I am attempting to add a recipient dynamically to the requiredAttendees for an Outlook appointment
var arr = [{emailAddress: 'test#example.com', displayName: 'Test Name'}]
Office.context.mailbox.item.requiredAttendees.addAsync(arr)
(also fails with arr = ['test#example.com'])
and it is throwing an error
Sys.ArgumentException: Sys.ArgumentException:
Value does not fall within the expected range.
How might that be accomplished?
Cf. docs which I am following
Cf. Radio-silence Github issue
UPDATE SCREEN SHOTS
PRE-THROW
You can notice that n is correctly defined as an array with 1 value (right panel)
Checking the same array as arr from the console evaluates to true
Throw
The script is throwing on evaluation (as indicated by the light green highlight)
To get dynamic URL params, I am loading an iframe onInit when Office is done initializing.
Though the rest of the API is available to the loaded iframe when passed in, there is something inherent to this particular piece of the API that must be dependent on window.
Moving the API call outside of the iframe fixes the issue and causes it to work as expected.
The error message is "make sure this cross-domain message is being sent to the intended domain".
This check rule from RSPEC-2819
Authors should not use the wildcard keyword ( *) in the targetOrigin argument in messages that contain any confidential information, as otherwise there is no way to guarantee that the message is only delivered to the recipient to which it was intended.
I assume it demands * cannot be used as targetOrigin, But It still shows warning when I use intended domain as targetOrigin like below:
Please somebody can tell me how to pass this check,
Any help would be appreciated
This rule detects only if a method postMessage is invoked on an object with a name containing window in it. Source code: PostMessageCheck.java. To bypass it, just assign your contentWindow object into different one, like this:
var content = this.elem.contentWindow;
content.postMessage('your message', window.location.origin);
Have faced similar issue in sonarQube. Below fix worked. Just get rid of using window object using directly.
Actual code:
window.parent.postMessage("data", parenturl);
Fix:
var content=window;
content.parent.postMessage("data",parenturl);
I have inherited responsibility for a project from a previous developer which takes incoming emails and processes them into customer support tickets.
It mostly works fine but it is having problems with one particular email and I can't work out why.
In Outlook the email clearly has a body (some short text, an image and a signature). It is a new message and not a reply.
The exchange server version is 2013.
But when being processed by the code below UniqueBody is empty, while Body contains the correct text. This does not happen with any other emails I've come across on that server.
if (serverVersion >= ExchangeVersion.Exchange2010)
body = msg.UniqueBody.Text;
else
body = msg.Body.Text;
What would cause UniqueBody to be empty while Body is not?
Why would the previous developer prefer to use UniqueBody over Body, how do they differ?
Could be related to this?
Check if you request the properties correctly:
PropertySet ps = new PropertySet(ItemSchema.UniqueBody);
var email = EmailMessage.Bind(service, item.ItemId, ps);
If you do so, the UniqueBody-Property should not be empty.
As far as I know, UniqueBody should be set by the exchange-server to show you which part of the mail is relevant for your ticket:
https://msdn.microsoft.com/en-us/library/office/dd877075(v=exchg.150).aspx
If your customer answers later to the ticket-conversation, you only want the new text.
With a new mail/ticket: body == uniqueBody == "the text you want to use".
I am making an outlook plugin in visual studio and part of it requires gathering the recipients/subject/body content. I am able to gather the subject and body without problem but accessing mailItem.To I always find it's blank.
body = mailItem.Body
subject = mailItem.Subject
Dim readtest As String = mailItem.To
Is the code I am using, and what makes it worse is that if I put a breakpoint in before trying to populate readtest and then I manually just look at the mailItem.To value and resume or step through the code it will work just fine.
Does anyone know how I can get this working properly?
You could try to get the same functionality with mailItem.Recipients property.
It returns IEnumerable. Recipient object have a Name member so basically you could do the following (It's in C# but i think you could figure it out with vb):
string recipients = string.Empty;
foreach (Outlook.Recipient r in mailItem.Recipients)
{
recipients += r.Name + ";";
}
You should get the same result as if you use mailItem.To