SOmething odd is happening. I'm trying to copy and move and item from a local MAPI folder to a remtoe Sent Items folder using GetSharedDefaultFolder. It works for the inbox folder but not sent items, even though i have permissions to it. Any ideas would be great thank you.
The Error is 'Could not complete the operation. One or more parameter values are not valid'
The code sample is:
Outlook.MailItem cItem = (mailmsg as Outlook.MailItem).Copy() as Outlook.MailItem;
Outlook.NameSpace ns = this.Application.GetNamespace("MAPI");
//ns.Logon()
Outlook.Recipient recipient = ns.CreateRecipient("realusera#domain.com");
recipient.Resolve();
if (recipient.Resolved)
{
MessageBox.Show("Resolved user");
Outlook.MAPIFolder mapifld = ns.GetSharedDefaultFolder(recipient, Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail);
cItem = (Outlook.MailItem)cItem.Move(mapifld);
}
According to MS documentation on this API, the olFolderSentMail is one of the default folders that is NOT allowed.
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._namespace.getshareddefaultfolder.aspx
Excerpt:
FolderType can be one of the following OlDefaultFolders constants: olFolderCalendar, olFolderContacts, olFolderDrafts, olFolderInbox, olFolderJournal, olFolderNotes, or olFolderTasks. (The constants olFolderDeletedItems, olFolderOutbox, olFolderJunk, olFolderConflicts, olFolderLocalFailures, olFolderServerFailures, olFolderSyncIssues, olPublicFoldersAllPublicFolders, olFolderRssSubscriptions, olFolderToDo, olFolderManagedEmail, and olFolderSentMail cannot be specified for this argument.)
Related
How can I iterate over all opened (or maybe pinned) calendars in Outlook (as in picture below)?
The top (mine calendar) I can find by:
NameSpace mapiNamespace = outlookApp.GetNamespace("MAPI");
MAPIFolder ownerFolder = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
The below (shared calendars) I can find by:
NameSpace mapiNamespace = outlookApp.GetNamespace("MAPI");
Recipient recipient = mapiNamespace.CreateRecipient("*******Test*****");
if (recipient.Resolve())
{
MAPIFolder sharedFolder = mapiNamespace.GetSharedDefaultFolder(recipient, OlDefaultFolders.olFolderCalendar);
}
But how to iterate opened (or maybe pinned) shared calendars without knowledge of recipient?
Thank you in advance for your answer.
I have a task which i need to create a program that converts outlook email to pdf.
this is my code
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
NameSpace outlookNs = app.GetNamespace("MAPI");
MAPIFolder rootFolder = outlookNs.Stores["Blah"].GetRootFolder();
List<MailItem> mailItems = new List<MailItem>();
Folders subFolders = rootFolder.Folders;
foreach (Folder folder in subFolders)
{
if (folder.Name == "Inbox")
{
Items items = folder.Items;
foreach (object item in items)
{
if (item is MailItem)
{
MailItem mailItem = item as MailItem;
string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "New folder", mailItem.EntryID + mailItem.SenderName.Replace("/", "") + ".msg");
mailItem.SaveAs(fileName, Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG);
}
}
}
}
the code is working but the outlook contains thousands of email. The outlook prompt a message every 10 minutes similar to the screenshot below
is there a way to avoid getting the message? Programatically or a setting will do?
Basically, it's not related to the programming instead of it's related the outlook security settings.
For every version of outlook you can find the settings for this pop-up just follow the instruction on this blog.
You can do a setting in your out look.
Mine is outlook 2013.
File->options : a window opens
In the window select Trust Center
You can see a button Trust center Settings
Options in window changes. Select Programmatic access
UnCheck the radio button Never warn me about suspicious activity (not recommended)
Through program, you can change below registry settings:
Go to "HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\15.0\outlook\security"
Change below settings programatically:
PromptSimpleMAPISend -- 2
PromptSimpleMAPINameResolve -- 2
PromptSimpleMAPIOpenMessage -- 2
By default when outlook is installed, the above values comes with zero value. What I do in my program is, I turn them to "2" programatically just before sending the email and turn them back to zero later point of time.
I am using EWS for searching for and displaying emails. However the final step of the project is to save specific messages as .msg files on the file system. I understand that this is not possible with EWS, so I will need to use Interop.Outlook to accomplish this. My question is: What is the best way to find the Outlook message given the information available from EWS. I have attempted to associate the Message.Id and ConversationId obtained from exchange via EWS with Outlook's messageId but have so far been unsuccessful.
Here is my current (failed) code for finding the ConversationID:
OUTLOOK.Application olApp = new OUTLOOK.Application();
OUTLOOK.NameSpace olNS = olApp.GetNamespace("MAPI");
OUTLOOK.MAPIFolder oFolder = olNS.GetDefaultFolder(OUTLOOK.OlDefaultFolders.olFolderInbox);
OUTLOOK.Items oItems = oFolder.Items;
String sFilter = string.Format("#SQL=\"http://schemas.microsoft.com/mapi/proptag/0x1035001F\" = '{0}'", missive.ConversationID.UniqueId);
object obj = oItems.Find(sFilter);
OUTLOOK.MailItem oEmail = (OUTLOOK.MailItem)obj;
if (oEmail != null)
{
return oEmail;
}
else
{
throw new Exception("MAIL ITEM NOT IN OUTLOOK");
}
As a side: I was looking for a reference for Outlookd filters That is the property names for the [property]=value version; and the hex values for use with the #SQL version. Does someone have a link to a good reference for that?
There's a ConvertIdType request you can use; see: https://msdn.microsoft.com/en-us/library/office/bb856559(v=exchg.140).aspx.
For a listing of MAPI properties and their DASL names and property tag values, see: https://msdn.microsoft.com/en-us/library/office/cc815517.aspx. Although Outlook Spy is a great tool for this as well.
I'm trying to get the body(or any other attribute) of an email which is inside a specific folder in outlook.
I'm using the interop.outlook assembly.
I have done the following so far. But when trying to call an item in myInbox, there are no attributes at all.
Application myApp = new ApplicationClass();
NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Folders["QC"];
The following brings no expected attributes
myInbox.Items[1].
In addition, the next step is to click a link inside the body of the email. just want to know if it's even possible.
Any help will be much appreciated.
This is how I'm doing;
Outlook.Application myApp = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Folders["QC"];
This should bring all mails in Inbox. Then call;
Outlook.MailItem mailItem = myInbox.Items[1];
This mailItem contains all the attributes you need.
Explanation: The mailFolder.Items[1] is an Outlook.Items object which has no attributes you require. You need to cast it to an Outlook.MailItem object to achieve this.
I'm using ExchangeServer 2010 SP2
and Outlook 2013
First I'm saving a Mail to the Draft folder using EWS
EmailMessage.Save()
After that I'm trying to open the mail via Interop
but I'm getting a COMException that the item doesn't exist
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace mapi = app.GetNamespace("MAPI");
Outlook.MAPIFolder draftFolder = mapi.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts);
//Custom function to get EntryID
string entryId = GetMessageId(email,IdFormat.HexEntryId);
string storeId = draftFolder.StoreID;
MailItem item = null;
try
{
item = mapi.GetItemFromID(entryId, storeId);
}
catch (COMException)
{
//Item not found
}
Is there any way to force Outlook to sync the Draft folder with the Exchange server?
I have used
Session.SendAndRecieve(true)
but it doesn't show any effect and I can't find any other Interop functions doing the desired thing.
EDIT: When disabling Cache-Mode everything runs fine but as soon as I turn it on I have no clue how to force it to get the Message
Thank you very much!
You can either
wait until the sync finishes - use Namespace.SyncObjects collection, retrieve the first SyncObject object, call SyncObject.Start and wait for the SyncObject.SyncEnd event to fire.
On the Extended MAPI level (C++ or Delphi) or Redemption (I am its author, it wraps Extended MAPI and can be used in any language), open the message in the online mode by using the MAPI_NO_CACHE (0x200) flag (IMsgStore::OpenEntry in Extended MAPI or RDOStore.GetMessageFromID in Redemption).