Is there a method or any way to receive or get new emails from the server for the Lotus Notes Domino object in C sharp?
When looping through the Inbox view all I get is existing emails and not new emails. So I am trying to initiate a receive.
"Unread marks" or "Unread email" is a unique function to Lotus Notes that is not exposed as an API in Java or .Net. But you can programmatically emulate it without too much complexity. Is it possible for you to try this:
If your CSharp object can have a "last Checked" date/time value that is set when you traverse the inbox.
Now whilst looping through the inbox, get the created date of each document.
In the case of email in a Lotus Notes database, this is the date the email hit the account. So it should be a fairly reliable means of determining the arrival date of the email.
The created date property is under the NotesDocument object as "created". This should return a date/time value that you can use. Any document that is newer than the "last checked" value would therefore be new mail.
If you have a particularly large inbox to loop through, you can get the inbox object (which can be treated like a view), and also use "GetAllUnreadEntries" method on the NotesView object.
Links to example code is in links above.
If you're running into a situation where new emails are added to the view you are looping through after you've started looping, then you can call the NotesView.Refresh method to update the NotesView object.
Otherwise the NotesView object will contain all the emails in the view. If by "new" you're talking about unread emails, that's a different story. Notes 8.0 introduces a method called GetAllUnreadEntries which would help you navigate through any unread view entries. The backend document itself doesn't store a read/unread property.
Hope this helps!
Related
I am writing a C# application where I want to loop through the 500 most recent emails in a given folder. The reason is because getting all the emails takes a long time using the below lines:
MAPIFolder folder = outlookApp.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox);
List<MailItem> items = folder.Items.OfType<MailItem>().ToList();
However, I know that what I am searching for each time is always going to be a recent email, so there's no need to get an entire year's worth of emails each time (over 8000, and I get less emails than the average employee at my job).
So, is there a way to only retrieve a certain amount of emails from a folder with Microsoft.Office.Interop.Outlook? Thanks in advance.
Iterating over all items in the folder is not really a good idea:
List<MailItem> items = folder.Items.OfType<MailItem>().ToList();
Instead, you need to use the Find/FindNext or Restrict methods of the Items class. They allow getting only items that correspond to your conditions. Read more about these methods in the following articles:
How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
How To: Use Restrict method to retrieve Outlook mail items from a folder
Instead of getting recent 500 emails you may retrieve emails for a day, few days, week and etc. So, you can process items in bunch. For example:
criteria = "[ReceivedTime] > '" _
& Format$("6/12/20 3:30PM","General Date") & "'"
You may find the Filtering Items Using a Date-time Comparison article helpful.
Extreme novice with C# here. I'm attempting to get a count for the number of emails that have a subject line that begins with "RE:" that were sent to me within the last month. For example something like below but instead of restricting to emails that only have "RE:" as the subject, I'd like to restrict only to emails that have a subject line beginning with "RE:" and that have a sent date within the last month. Any help would be much much appreciated. Thank you!
Outlook.Items repliedItems = inbox.Items.Restrict(#"[Subject] = ""RE:""");
You can use DASL queries with the ci_startswith or ci_phrasematch operators. For example, the following query performs a phrase match query for RE: in the message subject:
filter = "#SQL=\"http://schemas.microsoft.com/mapi/proptag/0x0037001E\" ci_phrasematch 'RE:'"
Also you'd need to combine another search criteria to the string passed to the Restrict method - items were sent to me within the last month. Use the MailItem.ReceivedTime property which returns a date indicating the date and time at which the item was received. The following articles explains how to use DateTime structures for filtering items in Outlook:
How To: Use Restrict method in Outlook to get calendar items
How To: Retrieve Outlook calendar items using Find and FindNext methods
Everyday,I need to hand more then 100 emails,and now I want dispatch these email to my partner,who can help me reply these email,but I want to detect which email is replied,and which is not.so I want to create a relation between email and the reply of this email,the relations are stored in our database,but I can't find relations between email and email's reply,I want you can help me.
You can use the Conversation object from the Outlook object model which represents a conversation that includes one or more items stored in one or more folders and stores. A conversation represents one or more items in one or more folders and stores. If you move an item in a conversation to the Deleted Items folder and subsequently enumerate the conversation by using the GetChildren, GetRootItems, or GetTable method, the item will not be included in the returned object. See How to: Get and Display Items in a Conversation for more information.
I recently posted a question about saving an email once it's sent - I have just about everything working, except for one small detail. Basically, I am able to catch an email right before it sends, and do whatever I want with it - in my case, save it. However, if you try to access that email's CreationTime attribute, it returns January 1st 4501 at 12AM. This is most likely because it hasn't actually been 'created' yet, in that it will be created in the Sent items folder as soon as my code finishes executing and it actually sends.
I'd like to leave this MailItem, which is about to be sent, untouched. I would like to duplicate it, change the CreationTime attribute of the duplicate to DateTime.Now, then save the duplicate, then allow Outlook to continue sending the original. However, when I attempt to modify the CreationTime, I get an error that that attribute is read-only. Is there any way to 'break into' it? Or any way to force a write or something?
A better approach is attaching to the sent items Folder.ItemAdd so you can save messages after they have been sent instead of before - that way your MailItem.CreationTime should be accurate. This may or may not be an option for you but could alleviate the issue.
Outlook.Folder sentItems = ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail) as Outlook.Folder;
sentItems.Items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(sentItems_ItemAdd);
// ...
void sentItems_ItemAdd(object Item)
{
var msg = Item as Outlook.MailItem;
msg.SaveAs(yourPath, Outlook.OlSaveAsType.olMSG);
}
Note: You need to handle proper COM resource disposal and error handling.
I have a Nsf file in which in one of folder there are some mail and notes items.
I am differentiating each item with "form" property.
In case of mails form type is "memo" but in above scenario Notes "form" type is again "memo"
How can i differentiate these two items?
thanx
Using the "form" item is not a safe way to distinguish emails from other "documents". In fact, a Notes data store does not really distinguish where a document came from - whether from a delivered email or a created document. However, you can use the fields RouteTimes and RouteServers to take a pretty good guess as to whether a given document was initiated from an email message. (The existence of either field will generally mean the document was delivered by the mail router).
If you want to compare the fields, I think the best way is to compare $ fields because they are usually reserved for internal use and should not be updated without a good reason. Therefore they are the most accurate fields of a form.
Check $MessageID, $MIMETrack or $UpdatedBy. This last one should be used with care but it should contains the mail server(s) if it is a mail.
In LN you can mock a the mail template in a note. So there is no sure way to distinguish a note from a mail UNLESS you know how the notes were created and use that info to build a test based on specific conditions. If you can control the note creation, I suggest to use a specific form to be able to distinguish each record type.
Of course you can check the properties (fields and values) of your notes and build a test "heuristically" (meaning rule-of-thumb)