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.
Related
Hi I had a requirement wherein I convert dxl to .msg file. Since there is no out of the box .NET way to do so, I parsed the xml, got the required fields out, created a .msg file using Microsoft.Office.Interop.Outlook. But when I open the file it looks like a draft mail, ready to be sent. But I would want the file to open as an inbox mail or a sent mail, wherein the fields are 'Not Editable' meaning should be readonly.
My code:
mailitem.To = "reciever#recieve.com";
mailitem.SentOnBehalfOfName = "sender#send.com";
mailitem.Subject = "Test for MSG";
mailitem.Body = "Sample Body";
mailitem.SaveAs(temppath + ".msg", OlSaveAsType.olMSG);
There is something called SaveSentMessageFolder in mailItem, couldn't figure out how to do so.
Thanks
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.
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.
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?
I'm trying to position an attachment in an RTF mail of Outlook 2007 created via COM:
using Outlook = Microsoft.Office.Interop.Outlook;
// ...
private static void CreateMailWithAttachment()
{
Outlook.Application ol = new Outlook.Application();
Outlook.MailItem mail = (Outlook.MailItem) ol.CreateItem(Outlook.OlItemType.olMailItem);
mail.BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
mail.Subject = "Important e-mail";
mail.Body = "1234567890 1234567890 1234567890";
mail.Attachments.Add(#"c:\myfile.txt", Outlook.OlAttachmentType.olByValue, 2);
mail.Display();
}
The documentation of Attachments.Add does not explicitly say what happens when a value between 2 and the length of the mail is used:
This parameter applies only to e-mail messages using Microsoft Outlook Rich Text format: it is the position where the attachment should be placed within the body text of the message. A value of 1 for the Position parameter specifies that the attachment should be positioned at the beginning of the message body. A value 'n' greater than the number of characters in the body of the e-mail item specifies that the attachment should be placed at the end. A value of 0 makes the attachment hidden.
I'm seeing the following behavior:
0: Works as described, attachment is hidden.
1: Does not work as described, attachment is at the end of the body.
> 1: Attachment is at the end of the body.
It's the same when starting Outlook with command line arguments /noextensions or /safe.
Is it possible to position an attachment in the middle of a mail? Am I missing something?
I guess it's KB967677, although I'm pretty sure the patch is installed. It works perfectly with Outlook 2003.
Sorry for bothering.