C# - Mail confirmation Outlook - c#

I am developing an app that checks an Outlook mail account, finds all the attachments and then print them out. At this point, the mails analyzed are moved to another folder.
I have only one problem: sometimes, I receive some mails with reading confirmation. The app checks the attachment, and when it has to move the mail, it freezes. Then a popup appear in Outlook, about sending or not sending the reading confirmation.
Now, I want to make this programmatically, I always want to send a reading confirmation when it is requested.
I found a property (ReadReceiptRequested), set to true if there is a reading confirmation to send, but I don't know how to send it.
Here a piece of the code I use:
//I store all the emails in a List<Outlook.MailItem> named emails
Outlook.Application myApp = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
//Check if the mail has read confirmation
if (emails[right_index].ReadReceiptRequested)
{
//How to send read confirmation?
}
//I read the mail, then I move it to another folder
emails[indice_scelto].UnRead = false;
emails[indice_scelto].Move(mapiNameSpace.Folders["New folder"]);
Could you help me?
Thanks in advance!

You can do that on the Extended MAPI level (C++ or Delphi) - call IMessage::SetReadFlag() - pass 0 to send read receipts or SUPPRESS_RECEIPT otherwise.
If Redemption is an option (I am its author), it exposes the RDOMail.MarkRead method that takes a SuppressReceipt Boolean parameter.

The Outlook object model doesn't provide any property or method. All you can is to set the UnRead property to false and Save the item.
Then you can begin synchronizing a user's folders using the specified Send\Receive group using the Start method of the SyncObject class. The Namespace class provides the SyncObjects property which returns a SyncObjects collection containing all Send\Receive groups. For example:
Public Sub Sync()
Dim nsp As Outlook.NameSpace
Dim sycs As Outlook.SyncObjects
Dim syc As Outlook.SyncObject
Dim i As Integer
Dim strPrompt As Integer
Set nsp = Application.GetNamespace("MAPI")
Set sycs = nsp.SyncObjects
For i = 1 To sycs.Count
Set syc = sycs.Item(i)
strPrompt = MsgBox( _
"Do you wish to synchronize " & syc.Name &"?", vbYesNo)
If strPrompt = vbYes Then
syc.Start
End If
Next
End Sub
I suppose then you can move the item wherever you need.

Related

determine if a message was sent or closed outlook

in c # I create a message m before sending it I show the user who can edit it and send or close it. How can I track the user closed this message or sent.
OutLookRef.Application oApp;
oApp = new OutLookRef.Application();
OutLookRef.MailItem mail = oApp.CreateItem(OutLookRef.OlItemType.olMailItem);
var pInspector = mail.GetInspector;
mail.Recipients.Add(address);
mail.Subject = subject;
mail.HTMLBody = body;
mail.Display();
All I got was to pause the code while this window is open
while (pInspector.CurrentItem is OutLookRef.MailItem)
{
System.Threading.Thread.Sleep(500);
}
also after sending, I would like to save this message to a disk, let's say mail.msg
It seems you are interested in the following properties:
MailItem.SendUsingAccount returns an Account object that represents the account under which the MailItem is to be sent.
MailItem.SentOnBehalfOfName returns a string indicating the display name for the intended sender of the mail message.
Namespace.CurrentUser returns the display name of the currently logged-on user as a Recipient object.
also after sending, I would like to save this message to a disk, let's say mail.msg
You may hook up to the ItemAdd event of the Items class which belongs to the Sent Items folder where you can save the item on the disk. The MailItem.SaveAs method saves the Microsoft Outlook item to the specified path and in the format of the specified file type. If the file type is not specified, the MSG format (.msg) is used.

Get sub messages from Outlook .msg files

I need to parse a few .msg files which have trail mails. Is there any way to get the sub messages and identify the initiated and the responded emails.
I do not want to use any third party tools. I am allowed to use the Outlook interop.
Below is the code that I have used to read the msg file.I am able to get the Body ,HTMLBody and other details.But I actually need all the trailing messages.
outlook._Application app = null;
outlook.MailItem item = null;
outlook.NameSpace session = null;
try
{
app = new outlook.Application();
session = app.Session;
item = session.OpenSharedItem(file) as outlook.MailItem;
}
catch(Exception ex)
{ }
If you are limited to OOM only, the only way to do that is to save each embedded message attachment as an MSG file (Attachment.SaveAsFile), then open it using Namespace.OpenSharedItem.
If using Redemption (I am its author) is an option, an MSG file can be opened using RDOSession.GetMessageFromMsgFile (similar to Namespace.OpenSharedItem in OOM), and the embedded message attachment can be accessed using the RDOAttachment.EmbeddedMsg property (returns RDOMail object) - no need to save the attachment first.

Get sent message in Outlook Addin

I am facing some problems trying to get the sent message from an Outlook plugin.
In onItemSend event, I open a dialog where it shows some fields, with message information such as recipients, subject, etc and a button that will save these information into our DB. Another requirement is to save a copy of the sent message and this is where I got stuck...
I could save the message using the SaveAs method but the problem is when I open the message, it shows:
This message has not been sent. This message will be sent via
Microsoft Exchange
causing some problems with users, making them think that the message was not sent.
During my searches, I found this thread where another person had the same problem and the solution was to use the message as PostItem instead of MailItem, once the PostItem is created in sent state. Also, we should set the MessageClass property to IPM.Note and delete PR_ICON_INDEX
Here is the code that I am using to do the steps above. I found this code here and changed a little bit:
PostItem postItem = this._email.Application.CreateItem(OlItemType.olPostItem);
postItem.MessageClass = "IPM.Note";
PropertyAccessor pa = postItem.PropertyAccessor;
pa.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x10800003", -1);
postItem.Save();
NameSpace session = postItem.Session;
string postItemEntryID = postItem.EntryID;
Marshal.ReleaseComObject(postItem);
Marshal.ReleaseComObject(pa);
MailItem newMessage = session.GetItemFromID(postItemEntryID) as MailItem;
newMessage.BCC = this._email.BCC;
newMessage.Body = this._email.Body;
newMessage.BodyFormat = this._email.BodyFormat;
newMessage.CC = this._email.CC;
newMessage.HTMLBody = this._email.HTMLBody;
//Hard coded path just for illustration
newMessage.SaveAs("C:\\Temp\\MSG\test.msg", OlSaveAsType.olMSG);
The code above creates a postitem object, set some of the properties and save to the path correctly, but it has the following problems:
After executing postItem.save, to create the postitem message, it creates a read message in inbox folder
After saving the messages, I have compared the files and the size where significant, the original message size was 580kb and the postitem saved message was 52kb. It seems it did not make a copy of the message
It lost some of the of the images embedded in message, such as signature images, showing a red X in place.
How can I get/create a message, with the exact message content, recipients, attachments, properties, etc (clone kind) with sent state, without creating another message inside inbox folder?
Thank you
I would not do this to a message that Outlook is trying to send. You can
Process the Items.ItemAdd event on the Sent Items folder. By that time the message is sent and all the sender related properties are set.
You can "fix" the created MSG file by removing the unsent flag. You can do that using Redemption (I am its author) - call RDOSession.GetMessageFromMsgFile / RDOMail.Sent = true / RDOMail.Save. Keep in mind that the sender information might not yet be set.
i would not go that way with the "postitem" further, somehow it does not look the perfect way for me.
the Problem is that you are copying the item bevor it is sent. Therefore the copy says it has not been sent.
If you do not need the "normal" copy which is saved in the "sent items"-Folder, you could just Change the Folder where the item is saved with
Set mailitem.SaveSentMessageFolder = someother Folder '(which is defined as Outlook.folder)
if that is not possible, then I would make an inspection (in ThisOutlookSession) of the "sent items" Folder and make the copy-action for every new item in there. If you don't know how to let me know, then I copy you some code to bring you on the way.
another question just because Iam curious: why are you opening the form and waiting for someone to hit the ok-button, instead of saving the data into your db straight away?

Get Signatures from Outlook and Detecting Body format

I am using COM API to compose an e-mail.
objOutlook = new Microsoft.Office.Interop.Outlook.Application();
mic = (Microsoft.Office.Interop.Outlook.MailItem)(objOutlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem));
mic.To = ccase.Email;
mic.CC = ccase.CC;
mic.Subject = ccase.Subject;
mic.Body = bodyBuffer.ToString();
// below line throws exception ?? Shouldn't it just use what is defined in outlook.
mic.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatUnspecified;
Question:
I want to define body to be plain Text, HTML, or Rich Text based upon what is defined in Outlook by the customer.
How can I retrieve the e-mail signature from Outlook and add it to the end of body ?
Any pointers will be appreciated.
Karephul
We decided not to do this as users might have configured multiple signatures. So, let users add signature in the end.

Using CreateItemFromTemplate to process an olEmbeddeditem Outlook attachment

I am using C# to process a message in my Outlook inbox that contains attachments. One of the attachments is of type olEmbeddeditem. I need to be able to process the contents of that attachment. From what I can tell I need to save the attachment to disk and use CreateItemFromTemplate which would return an object.
The issue I have is that an olEmbeddeditem can be any of the Outlook object types MailItem, ContactItem, MeetingItem, etc. How do you know which object type a particular olEmbeddeditem attachment is going to be so that you know the object that will be returned by CreateItemFromTemplate?
Alternatively, if there is a better way to get olEmbeddeditem attachment contents into an object for processing I'd be open to that too.
I found the following code on Google Groups for determining the type of an Outlook object:
Type t = SomeOutlookObject.GetType();
string messageClass = t.InvokeMember("MessageClass",
BindingFlags.Public |
BindingFlags.GetField |
BindingFlags.GetProperty,
null,
SomeOutlookObject,
new object[]{}).ToString();
Console.WriteLine("\tType: " + messageClass);
I don't know if that helps with an olEmbedded item, but it seems to identify regular messages, calendar items, etc.
Working with email attachments that are also emails which in turn contains user defined properties that I want to access, then I perform the following steps:
Outlook.Application mailApplication = new Outlook.Application();
Outlook.NameSpace mailNameSpace = mailApplication.GetNamespace(“mapi”);
// make sure it is an embedded item
If(myAttachment.Type == Outlook.OlAttachmentType.olEmbeddeditem)
{
myAttachment.Type.SaveAsFile(“temp.msg”);
Outlook.MailItem attachedEmail = (Outlook.MailItem)mailNameSpace.OpenSharedItem(“temp.msg”);
String customProperty = attachedEmail.PropertyAccessor.GetProperty(
“http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-c000-000000000046}/myProp
}
If you open the MailItem using, then I will not have access to the properties as mentioned above:
Outlook.MailItem attachedEmail = (Outlook.MailItem)mailApplication.CreateFromTemplate(“temp.msg”);

Categories

Resources