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.
Related
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.
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
What's the proper way to set a MailItem as read before opening or set the value suppress_receipt in PR_MESSAGE_FLAGS?
Looking at http://msdn.microsoft.com/en-us/library/office/cc815395(v=office.12).aspx my code is:
MailItem x = item as MailItem;
x.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E070003",35);
I got 35 from other read mails using OutlookSpy, assuming it contains the boolean flag for "Read".
Running this code gets me the exception "The operation failed".
Any ideas?
Thanks.
You cannot do that in the Outlook Object Model. On the MAPI level, you need to call IMessage::SetReadFlag(SUPPRESS_RECEIPT), but you will need C++ or Delphi for that.
If using Redemption (I am its author) is an option, you can use RDOMail.MarkRead(SuppressReceipt) (can be called from any language)
Use:
string PR_CLIENT_READ = "http://schemas.microsoft.com/mapi/proptag/0x0E070003"; omMailItem.PropertyAccessor.SetProperty(PR_CLIENT_READ, 0x09);
Worked for me..
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?
I am using coltware.airxmail to send emails from my Flex app.
I would like to send VCalendar appointment files generated from Flex straight to Outlook so they are opened in the Calender view. I am able to send the VCal files as an attachment on an email, however, these are not "auto-opened" in Outlook Calendar, which requires the user to double click on the file.
I have been trying to set the content type of the mail to "text/x-vCalendar", and pass in a byte array containing the VCal file, however, no joy. The vCal arrives as a .txt attachment to an empty email!
I wonder if anyone has had previous experience with this kit, or can suggest any pointers?
Or even suggest another component they have used to send VCal files straight to outlook, from ActionScript?
Here's my sample code (DEMO CODE VERY MESSY JUST TO GET POINT ACROSS):
var sender:SMTPSender = new SMTPSender();
// Set the from / to / host / port values here
var contentType:ContentType = new ContentType();
contentType.setMainType("text/x-vCalendar");
var message:MimeMessage = new MimeMessage(contentType,"UTF-8");
var file:File = File.desktopDirectory.resolvePath("vcal.vcs");
file.addEventListener(Event.COMPLETE,
function(ev:Event):void {
message.addRawContent(file.data);
sender.send(message);
sender.close();
});
file.load();
Hopefully I can achieve this using the coltware component. There's nothing on their site about using these methods, although the API guide is very incomplete - just "basic usage"... http://code.google.com/p/airxmail/wiki/HowToUseAPI
Did you try using a different content type, such as "text/calendar"? see here: http://weblogs.asp.net/bradvincent/archive/2008/01/16/creating-vcalendars-programmatically.aspx