public static void ReadAndReplaceMessageBody() { // String path = @"C:\Email\"; MapiMessage msg = MapiMessage.FromFile("Test Links.msg"); String URLToReplace = "www.aspose.com"; if (msg.BodyType == BodyContentType.Html) { //Extract HTML Body var bodyHtml = msg.BodyHtml; //Setting Regex for finding hyperlink Regex rs = new Regex(@"<a.*?href=(""|')(?<href>.*?)(""|').*?>(?<value>.*?)</a>"); foreach (Match match in rs.Matches(bodyHtml)) { //Extrct URL string url = match.Groups["href"].Value; //Replace URL bodyHtml = bodyHtml.Replace(url, URLToReplace); } //Setting new body msg.Body = bodyHtml; } //Save MSG Aspose.Email.SaveOptions options = new MsgSaveOptions(MailMessageSaveType.OutlookMessageFormatUnicode); msg.Save(@"Test Links_SavedMsg.msg", options); }
public static void Run() { //ExStart:ReadNamedMAPIProperties // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); // Load from file MapiMessage message = MapiMessage.FromFile(dataDir + @"message.msg"); // Get all named MAPI properties MapiPropertyCollection properties = message.NamedProperties; // Read all properties in foreach loop foreach (MapiNamedProperty mapiNamedProp in properties.Values) { // Read any specific property switch (mapiNamedProp.NameId) { case "TEST": Console.WriteLine("{0} = {1}", mapiNamedProp.NameId, mapiNamedProp.GetString()); break; case "MYPROP": Console.WriteLine("{0} = {1}", mapiNamedProp.NameId, mapiNamedProp.GetString()); break; default: break; } } //ExEnd:ReadNamedMAPIProperties }
public static void Run() { // ExStart:LoadMSGFiles // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); // Create an instance of MapiMessage from file MapiMessage msg = MapiMessage.FromFile(dataDir + @"message.msg"); // Get subject Console.WriteLine("Subject:" + msg.Subject); // Get from address Console.WriteLine("From:" + msg.SenderEmailAddress); // Get body Console.WriteLine("Body" + msg.Body); // Get recipients information Console.WriteLine("Recipient: " + msg.Recipients); // Get attachments foreach (MapiAttachment att in msg.Attachments) { Console.Write("Attachment Name: " + att.FileName); Console.Write("Attachment Display Name: " + att.DisplayName); } // ExEnd:LoadMSGFiles }
public static void Run() { // ExStart:RecipientInformation // The path to the File directory. string dataDir = RunExamples.GetDataDir_POP3(); string dstEmail = dataDir + "Message.msg"; // Load message file and Enumerate the recipients MapiMessage message = MapiMessage.FromFile(dstEmail); foreach (MapiRecipient recip in message.Recipients) { switch (recip.RecipientType) // What's the type? { case MapiRecipientType.MAPI_TO: Console.WriteLine("RecipientType:TO"); break; case MapiRecipientType.MAPI_CC: Console.WriteLine("RecipientType:CC"); break; case MapiRecipientType.MAPI_BCC: Console.WriteLine("RecipientType:BCC"); break; } // Get email address, display name and address type Console.WriteLine("Email Address: " + recip.EmailAddress); Console.WriteLine("DisplayName: " + recip.DisplayName); Console.WriteLine("AddressType: " + recip.AddressType); } // ExEnd:RecipientInformation Console.WriteLine(Environment.NewLine + "Displayed recipient information from MSG file " + dstEmail); }
public static void Run() { // ExStart:LoadingMSGFile string dataDir = RunExamples.GetDataDir_KnowledgeBase(); MapiMessage msg = MapiMessage.FromFile(dataDir + "Message.msg"); // ExEnd:LoadingMSGFile }
public static void Run() { // ExStart:AddMessagesToPSTFiles // The path to the file directory. string dataDir = RunExamples.GetDataDir_Outlook() + "AddMessagesToPSTFiles_out.pst"; if (File.Exists(dataDir)) { File.Delete(dataDir); } else { } // Create new PST PersonalStorage personalStorage = PersonalStorage.Create(dataDir, FileFormatVersion.Unicode); // Add new folder "Inbox" personalStorage.RootFolder.AddSubFolder("Inbox"); // Select the "Inbox" folder FolderInfo inboxFolder = personalStorage.RootFolder.GetSubFolder("Inbox"); // Add some messages to "Inbox" folder inboxFolder.AddMessage(MapiMessage.FromFile(RunExamples.GetDataDir_Outlook() + "MapiMsgWithPoll.msg")); // ExEnd:AddMessagesToPSTFiles }
public IActionResult Index() { string SourceFilePath = "D:\\Input.msg"; //Load the Message File SourceFilePath = @"/Users/mudassir/Documents/Email/Messages.msg"; //Reading Email Msg file MapiMessage msg = MapiMessage.FromFile(SourceFilePath); //Reading keys var allKeys = msg.Headers.AllKeys; // Generate rows and cells. int numRows = msg.Headers.Count() + 1; DataTable dt = new DataTable(); dt.Columns.Add("HeaderName"); dt.Columns.Add("Value"); //Iterating all Message headers and populating in table for (int rowNum = 1; rowNum < numRows; rowNum++) { DataRow dRow = dt.NewRow(); dRow["HeaderName"] = allKeys[rowNum - 1].ToString(); dRow["Value"] = msg.Headers[allKeys[rowNum - 1]].ToString(); dt.Rows.Add(dRow); } return(View(dt)); }
public static void Run() { // ExStart:ReadMapiNote // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage note = MapiMessage.FromFile(dataDir + "MapiNote.msg"); MapiNote note2 = (MapiNote)note.ToMapiMessageItem(); // ExEnd:ReadMapiNote }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); // ExStart:LoadingContactFromMSG MapiMessage msg = MapiMessage.FromFile(dataDir + "Contact.msg"); MapiContact mapiContact = (MapiContact)msg.ToMapiMessageItem(); // ExEnd:LoadingContactFromMSG }
public static void Run() { // ExStart:ReadFollowupFlagOptionsForMessage // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage mapi = MapiMessage.FromFile(dataDir + "message.msg"); FollowUpOptions options = FollowUpManager.GetOptions(mapi); // ExEnd:ReadFollowupFlagOptionsForMessage }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); // ExStart:ReadingMapiTask MapiMessage msg = MapiMessage.FromFile(dataDir + "MapiTask.msg"); MapiTask task2 = (MapiTask)msg.ToMapiMessageItem(); // ExEnd:ReadingMapiTask }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); string fileName = dataDir + "NewGroup.msg"; // ExStart:ReadingDistributionListFromPST MapiMessage message = MapiMessage.FromFile(fileName); MapiDistributionList dlist = (MapiDistributionList)message.ToMapiMessageItem(); // ExEnd:ReadingDistributionListFromPST }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage msg = MapiMessage.FromFile(dataDir + "MsgWithAtt.msg"); msg.Save(dataDir + "AttachmentsToRemove_out.msg"); // ExStart:RemoveAttachmentsFromFile MapiMessage.RemoveAttachments(dataDir + "AttachmentsToRemove_out.msg"); // ExEnd:RemoveAttachmentsFromFile }
public static void Run() { // ExStart:CreatingTNEFFromMSG // The path to the File directory. string dataDir = RunExamples.GetDataDir_Email(); MapiMessage msg = MapiMessage.FromFile(dataDir + "Message.msg"); MailMessageInterpretor mi = MailMessageInterpretorFactory.Instance.GetIntepretor(msg.MessageClass); MailMessage eml = mi.InterpretAsTnef(msg); // ExEnd:CreatingTNEFFromMSG }
public static void Run() { // ExStart:CheckPasswordProtection // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage mapiMessage = MapiMessage.FromFile(dataDir + "message1.msg"); FollowUpManager.MarkAsCompleted(mapiMessage); mapiMessage.Save(dataDir + "MarkedCompleted_out.msg"); }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage msg = MapiMessage.FromFile(dataDir + "MsgWithAtt.msg"); msg.Save(dataDir + "AttachmentsToDestroy_out.msg"); // ExStart:DestroyAttachment MapiMessage.DestroyAttachments(dataDir + "AttachmentsToDestroy_out.msg"); // ExEnd:DestroyAttachment }
public static void Run() { // ExStart:MarkFollowUpFlagAsCompleted // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage mapiMessage = MapiMessage.FromFile(dataDir + "Message.msg"); FollowUpManager.MarkAsCompleted(mapiMessage); mapiMessage.Save(dataDir + "MarkedCompleted_out.msg"); // ExEnd:MarkFollowUpFlagAsCompleted }
public static void Run() { // ExStart:CreatingTNEFFromMSG // The path to the File directory. string dataDir = RunExamples.GetDataDir_Email(); MapiMessage msg = MapiMessage.FromFile(dataDir + "Message.msg"); MailConversionOptions options = new MailConversionOptions { ConvertAsTnef = true }; MailMessage mail = msg.ToMailMessage(options); // ExEnd:CreatingTNEFFromMSG }
public static void Run() { // ExStart:AddVotingButtonToExistingMessage // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage mapi = MapiMessage.FromFile(dataDir + "message.msg"); FollowUpManager.AddVotingButton(mapi, "Indeed!"); mapi.Save(dataDir + "AddVotingButtonToExistingMessage_out.msg"); // ExEnd:AddVotingButtonToExistingMessage }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); // ExStart:EmbedMessageAsAttachment MapiMessage message = new MapiMessage("*****@*****.**", "*****@*****.**", "Subj", "This is a message body"); MapiMessage attachMsg = MapiMessage.FromFile(dataDir + "Message.msg"); message.Attachments.Add("Weekly report.msg", attachMsg); message.Save(dataDir + "WithEmbeddedMsg_out.msg"); // ExEnd:EmbedMessageAsAttachment }
public static void Run() { //ExStart:RemoveFollowUpflag // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); // Load file from Disk MapiMessage mapi = MapiMessage.FromFile(dataDir + "message.msg"); FollowUpManager.ClearFlag(mapi); mapi.Save(dataDir + "RemoveFollowUpflag_out.msg"); //ExEnd:RemoveFollowUpflag }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); string fileName = dataDir + "Test Meeting.msg"; // ExStart:DisplayRecipientsStatusFromMeetingRequest MapiMessage message = MapiMessage.FromFile(fileName); foreach (MapiRecipient recipient in message.Recipients) { Console.WriteLine(recipient.RecipientTrackStatus); } // ExEnd:DisplayRecipientsStatusFromMeetingRequest }
public static void Run() { string dataDir = RunExamples.GetDataDir_Email(); // ExStart:CreateTNEFEMLFromMSG MapiMessage mapiMsg = MapiMessage.FromFile(dataDir + "Message.msg"); MailConversionOptions mco = new MailConversionOptions(); mco.ConvertAsTnef = true; MailMessage message = mapiMsg.ToMailMessage(mco); // ExEnd:CreateTNEFEMLFromMSG }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); string fileName = dataDir + "WithEmbeddedMsg.msg"; // ExStart:ReadEmbeddedMessageFromAttachment var message = MapiMessage.FromFile(fileName); if (message.Attachments[0].ObjectData.IsOutlookMessage) { var getData = message.Attachments[0].ObjectData.ToMapiMessage(); } // ExEnd:ReadEmbeddedMessageFromAttachment }
public static void Run() { // ExStart:CreatForwardMessage // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage originalMsg = MapiMessage.FromFile(dataDir + "message1.msg"); ForwardMessageBuilder builder = new ForwardMessageBuilder(); builder.AdditionMode = OriginalMessageAdditionMode.Textpart; MapiMessage forwardMsg = builder.BuildResponse(originalMsg); forwardMsg.Save(dataDir + "forward_out.msg"); // ExStart:CreatForwardMessage }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); string fileName = dataDir + "MessageWithVotingButtons.msg"; // ExStart:ReadingVotingOptions MapiMessage message = MapiMessage.FromFile(fileName); // This method can be useful when except voting buttons it is necessary to get other parameters (ex. a category) FollowUpOptions options = FollowUpManager.GetOptions(message); // Voting buttons will be introduced as a string with semi-column as a separator string votingButtons = options.VotingButtons; // ExEnd:ReadingVotingOptions }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); string fileName = dataDir + "Test Meeting.msg"; MapiMessage message = MapiMessage.FromFile(fileName); MapiCalendar calendar = (MapiCalendar)message.ToMapiMessageItem(); // ExStart:CreateMapiCalendarTimeZoneFromStandardTimezone MapiCalendarTimeZone timeZone = new MapiCalendarTimeZone(TimeZoneInfo.Local); // ExEnd:CreateMapiCalendarTimeZoneFromStandardTimezone calendar.StartDateTimeZone = timeZone; calendar.EndDateTimeZone = timeZone; }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage message = MapiMessage.FromFile(dataDir + "messageWithEmbeddedEML.msg"); MapiAttachment attachment = message.Attachments[0]; // ExStart:GetNestedMailMessageAttachments // Create a MapiMessage object from the individual attachment MapiMessage getAttachment = MapiMessage.FromProperties(attachment.ObjectData.Properties); // Create object of type MailMessageImterpretor from the above message and Save the embedded message to file at disk MailMessage mailMessage = getAttachment.ToMailMessage(new MailConversionOptions()); mailMessage.Save(dataDir + @"NestedMailMessageAttachments_out.eml", SaveOptions.DefaultEml); // ExEnd:GetNestedMailMessageAttachments }
private void button1_Click(object sender, EventArgs e) { // ExStart:AsposeEmailOutlook // The path to the documents directory. string dataDir = RunExamples.GetDataDir_KnowledgeBase(); // Load the outlook message file MapiMessage msg1 = MapiMessage.FromFile(dataDir + "Message.msg"); // Use the public properties to assign the values to controls txtSubject.Text = msg1.Subject; txtFrom.Text = msg1.SenderEmailAddress; txtTo.Text = msg1.DisplayTo; txtBody.Text = msg1.Body; // ExEnd:AsposeEmailOutlook }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); string fileName = "outputAttachments.msg"; // ExStart:SaveAttachmentsFromOutlookMSGFile // Create an instance of MapiMessage from file MapiMessage message = MapiMessage.FromFile(dataDir + fileName); // Iterate through the attachments collection foreach (MapiAttachment attachment in message.Attachments) { // Save the individual attachment attachment.Save(dataDir + attachment.FileName); } // ExEnd:SaveAttachmentsFromOutlookMSGFile }