For my outlook addin I need to handle emails, calculate an unique hash and store this hash on a server/database. For example :
There are 4 users :
user1#company.com
user2#company.com
user3#company.com
randomperson#gmail.com
Case 1:
User1 sends a mail to User2 and User3. User2 wants to store the mailhash serverside, so he clicks an addin button. A hash is calculated with code like this
var accessor = mailItem.PropertyAccessor;
var subject = accessor.GetProperty(_PR_SUBJECT_W_TAG).ToString();
var messageId = accessor.GetProperty(_PR_INTERNET_MESSAGE_ID_W_TAG).ToString();
var hash = CalulateHash(subject + messageId);
This hash is stored on the server. If User3 tries to store the hash of the mail too, he gets the same hash (cause subject and messageid should be the same ==> rfc822) and the server knows, he got this hash already. This works very well.
Case 2:
User1 wants to send a mail to User2,User3 and randomperson. Cause randomperson doesn't belong to their company, User1 want to use the function SendAndStore(). Before the mail is send, a custom property is added to the new mail
mailItem.UserProperties.Add("HandleAfterSent", MSOutlook.OlUserPropertyType.olText);
var aasProp = mailItem.UserProperties.Find("HandleAfterSent");
if (aasProp != null)
{
aasProp.Value = "some_value";
}
mailItem.Save();
SendMailItem(mailItem);
Moreover, there is a possibility to get notified if a new item is added to a inboxfolder. So I observe the sent folder.
inbox = outlookNameSpace.GetDefaultFolder(MSOutlook.OlDefaultFolders.olFolderSentMail);
items = inbox.Items;
items.ItemAdd += OnInboxItemAdded;
If the mail is send via SendMailItem(mailItem);, the handler is called (works fine too). But unfortunately I have problems with calculating the hash of the send mail, cause this mail has no Message-ID. Does anyone have a idea, how to get the Message-ID of a mail, which was send just now.
I already tried to set the Message-ID on my own, but it is overriden from MS Exchange server.
EDIT :
Outlook is on cache mode. I need a possibility to get the Message-ID for this scenario too.
EDIT2 (in addition to comments) :
Case 3:
randomperson wants to send a mail to User1,User2 and User3. Cause randomperson doesn't belong to their company, User1 want to use the function StoreFromInbox(). Mails in the inbox of all three Users have the same Message-ID. But they have different _PR_SEARCH_KEY_ , so we can't use this property.
Try to use PR_SEARCH_KEY MAPI property - it should stay the same after the message is sent and moved to the Sent Items folder.
Related
I want to send two buttons in email. On clicking of that buttons user should be able to Approve or Reject approval. It should work on gmail as well as outlook. I am not sure if web api will work. I am using c# for sending email. Please share any idea.
Email clients (Outlook as well) don't allow executing any JavaScript code in the message body for security reasons. The best what you could do for all mail clients is to paste a hyperlink in the message body and count responses on the server side when users click it.
As for for Outlook, you can use the MailItem.VotingOptions property which allows setting a string specifying a delimited string containing the voting options for the mail message.
Voting options on messages are used to give message recipients a list of choices and to track their responses. To create voting options programmatically, set a string that is a semicolon-delimited list of values for the VotingOptions property of a MailItem object. The values for the VotingOptions property will appear under the Vote command in the Respond group in the ribbon of the received message.
using Outlook = Microsoft.Office.Interop.Outlook;
private void OrderPizza()
{
Outlook.MailItem mail = (Outlook.MailItem)Application.CreateItem(
Outlook.OlItemType.olMailItem);
mail.VotingOptions = “Cheese; Mushroom; Sausage; Combo; Veg Combo;”
mail.Subject = “Pizza Order”;
mail.Display(false);
}
How to compare e-mail messages without using the body of the message?
For example:
John sent a message to Mary and "save" this message in my addin.
Both have the same addin.
When Mary receives the message, this message must be categorized because John already "save" the message.
How to identify that the message that Mary received is the same as the message that John sent("save") without using the body of the message?
Currently this is working as follows, a HASH is made with the following information:
Sender
Addressee
Subject
Message Body Text
This Hash is stored in the database, when Mary's Outlook triggers the event of the new message, a HASH with the same information is generated and compared in the database to see if it should be categorized or not.
The problem is that depending on the body size of the message, it is not performatic, it takes a long time to get the body of the message through the MailItem.Body property.
The purpose of not using the body of the message is solely to increase performance.
public string GetAssinatura(Outlook.MailItem email)
{
try
{
string corpoEmail = email.Body;//this is not performatic with big messages
var hash = GenerateHash(corpoEmail);
}
}
Conversation participants can reply or forward the message, so Outlook and most of the most frequently used e-mail clients change the subject to a default, Re: Subject for example.
Therefore, it is not possible to only have a hash of the participants and the subject.
Using the property:
MailItem.SentOn
It's possible generate that hash. The sender Outlook only will have that info after send the message. So the code must run when a new item is add in the Item_Send folder.
I want to retrieve all mails in a conversation when a user selects an email.
I know that I can use this - https://msdn.microsoft.com/en-us/library/office/ff869870(v=office.15).aspx, but for some microsoft exchange accounts, getrootitems returning zero.
So, is there any other way that works for microsoft exchange ?
More details:
My outlook showing "Online with microsoft exchange" at bottom right.
Below process is slow as I have 1000's of mails in inbox, so this wont help me.
IEnumerable mail =
folder.Items.OfType().Where(m => m.Subject == "Test").Select(m => m);
The GetRootItems method of the Conversation class has the following description in MSDN:
If all items are deleted from the conversation after the Conversation object has been obtained, GetRootItems returns a SimpleItems collection with zero objects. In this case, the Count property of the SimpleItems collection returns 0.
Try to use the cached exchange mode instead.
I'm currently developing an application that handles mail for mailboxes automatically. We use the tool Outlook Redemption and connect with one service account to multiple Exchange mailboxes.
Case
The problem we face is forwarding mail from the original mailbox. Say service account 'A' is handling shared mailbox 'B' and is forwarding mail. I'd like the sender to be the mail address of 'B', but when I receive the mail the mail address of 'A' shows up as sender.
Source code
// Initialize the session with the service account.
_session = new RDOSession();
_session.LogonExchangeMailbox(configurationSettings.MailAddress, configurationSettings.Url);
// Connect to the target mailbox and retrieve mail message.
RDOStore store = _session.Stores.GetSharedMailbox(targetMailBox);
RDOMail originalMailItem = store.GetMessageFromID(entryId);
// Creates a forwarded version of the mail.
RDOMail forwardMailItem = originalMailItem.Forward();
// Set sender to target mailbox owner.
if (store is RDOExchangeMailboxStore)
{
forwardMailItem.Sender = ((RDOExchangeMailboxStore)store).Owner;
forwardMailItem.SenderEmailAddress = targetMailBox;
}
// Set recipient and send.
forwardMailItem.Recipients.Clear();
forwardMailItem.Recipients.Add(forwardMailAddress);
forwardMailItem.Send();
Questions
Anyone got a clue on a solution?
If this won't work, is it possible to get the mail address of 'B' in the 'On behalf of' rule?
Thanks in advance!!
The problem is that the message being forwarded is created in the primary store in the profile, not the delegate mailbox.
Besides setting the Sender property, have you tried to also set the SentOnBehalfOf property?
I am developing an OUTLOOK 2010 addin in C#. This addin will create activities based on conversation.
For example, one user create new email, others reply,forward or CC, treat this email chain as one converstaion thread. Thoes emails have the same mailItem.ConversationID.
Based on this conversationID, my program generated an activty, and link conversationid to the activity which can be seen in each email in this email chain.
It all works fine on my machine (I reply,forward,cc in the same email chain, it get the same conversationID). However when other user reply email trigger my program generate activities, it generated different ConverstationID (the same email chain).
My question is:
1.ConversationID works only in local? Like for the same email Chain in different user's machine, the conversationID is different?
2.Is there universal mailitem conversationID for one email chain as long as user is using the same version of OUTLOOK?
var mailItem = this.OutlookItem as OutlookNS.MailItem;
if (mailItem.ConversationID != null )
{
OutlookHelper.Conversation_Index = mailItem.ConversationIndex;
OutlookHelper.Conversation_Topic = mailItem.ConversationTopic;
OutlookHelper.Current_ConversationID = mailItem.ConversationID;
CreateActivity(mailItem.ConversationTopic,mailItem.ConversationID);
}
I already tried EntryID, this attribute is keep changing.
I figured it out myself.
All the email in the same email chain has the same first 44 character of ConversationIndex. Everytime when a new replyer reply this email, the ConversationIndex will append a new ramdon generated 44 characters string. It is a universal identity applied for user using differet machine. But when the subject of this email is changed, a brand new 44 charaters ConversationIndex will be generated. ConversationID only works in local to track emails in the same email chain