Response ConvertPstToMht(string fileName, string folderName)
        {
            return(ProcessTask(fileName, folderName, delegate(string inputFilePath, string outputFolderPath)
            {
                // Save as mht with header
                var mhtSaveOptions = new MhtSaveOptions
                {
                    //Specify formatting options required
                    //Here we are specifying to write header informations to output without writing extra print header
                    //and the output headers should display as the original headers in message
                    MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.DisplayAsOutlook,
                    // Check the body encoding for validity.
                    CheckBodyContentEncoding = true
                };

                using (var personalStorage = PersonalStorage.FromFile(inputFilePath))
                {
                    int i = 0;
                    HandleFolderAndSubfolders(mapiMessage =>
                    {
                        mapiMessage.Save(Path.Combine(outputFolderPath, "Message" + i++ + ".mht"), mhtSaveOptions);
                    }, personalStorage.RootFolder, new MailConversionOptions());
                }
            }));
        }
        public static void Run()
        {
            // ExStart:RenderingContactInformationToMhtml
            string dataDir = RunExamples.GetDataDir_Outlook();

            //Load VCF Contact and convert to MailMessage for rendering to MHTML
            MapiContact contact = MapiContact.FromVCard(dataDir + "Contact.vcf");

            MemoryStream ms = new MemoryStream();

            contact.Save(ms, ContactSaveFormat.Msg);
            ms.Position = 0;
            MapiMessage           msg = MapiMessage.FromStream(ms);
            MailConversionOptions op  = new MailConversionOptions();
            MailMessage           eml = msg.ToMailMessage(op);

            //Prepare the MHT format options
            MhtSaveOptions mhtSaveOptions = new MhtSaveOptions();

            mhtSaveOptions.CheckBodyContentEncoding   = true;
            mhtSaveOptions.PreserveOriginalBoundaries = true;
            MhtFormatOptions formatOp = MhtFormatOptions.WriteHeader | MhtFormatOptions.RenderVCardInfo;

            mhtSaveOptions.RenderedContactFields = ContactFieldsSet.NameInfo | ContactFieldsSet.PersonalInfo | ContactFieldsSet.Telephones | ContactFieldsSet.Events;
            mhtSaveOptions.MhtFormatOptions      = formatOp;
            eml.Save(dataDir + "ContactMhtml_out.mhtml", mhtSaveOptions);
            // ExEnd:RenderingContactInformationToMhtml
        }
Exemple #3
0
        Response ConvertMboxToMht(string fileName, string folderName)
        {
            return(ProcessTask(fileName, folderName, delegate(string inputFilePath, string outputFolderPath)
            {
                // Save as mht with header
                var mhtSaveOptions = new MhtSaveOptions
                {
                    //Specify formatting options required
                    //Here we are specifying to write header informations to output without writing extra print header
                    //and the output headers should display as the original headers in message
                    MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.DisplayAsOutlook,
                    // Check the body encoding for validity.
                    CheckBodyContentEncoding = true
                };

                using (var reader = new MboxrdStorageReader(inputFilePath, false))
                {
                    for (int i = 0; i < reader.GetTotalItemsCount(); i++)
                    {
                        var message = reader.ReadNextMessage();
                        message.Save(Path.Combine(outputFolderPath, "Message" + i + ".mht"), mhtSaveOptions);
                    }
                }
            }));
        }
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Email();

            // ExStart:ConvertMHTMLWithOptionalSettings
            MailMessage eml = MailMessage.Load(Path.Combine(dataDir, "Message.eml"));

            // Save as mht with header
            MhtSaveOptions mhtSaveOptions = new MhtSaveOptions
            {
                //Specify formatting options required
                //Here we are specifying to write header informations to outpu without writing extra print header
                //and the output headers should display as the original headers in message
                MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.DisplayAsOutlook,
                // Check the body encoding for validity.
                CheckBodyContentEncoding = true
            };

            eml.Save(Path.Combine(dataDir, "outMessage_out.mht"), mhtSaveOptions);
            // ExEnd:ConvertMHTMLWithOptionalSettings

            //ExStart: ConvertToMHTMLWithoutInlineImages
            mhtSaveOptions.SkipInlineImages = true;

            eml.Save(Path.Combine(dataDir, "EmlToMhtmlWithoutInlineImages_out.mht"), mhtSaveOptions);
            //ExEnd: ConvertToMHTMLWithoutInlineImages
        }
Exemple #5
0
        public static void Run()
        {
            //ExStart: ChangeFontWhileConvertingToMHT
            string dataDir = RunExamples.GetDataDir_Email();

            MailMessage eml = MailMessage.Load(dataDir + "Message.eml");

            MhtSaveOptions options      = SaveOptions.DefaultMhtml;
            int            cssInsertPos = options.CssStyles.LastIndexOf("</style>");

            options.CssStyles = options.CssStyles.Insert(cssInsertPos,
                                                         ".PlainText{" +
                                                         "    font-family: sans-serif;" +
                                                         "}"
                                                         );

            eml.Save("message.mhtml", options);
            //ExEnd: ChangeFontWhileConvertingToMHT
        }
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Outlook();
            //ExStart: ConvertMapiTaskToMHT
            MapiMessage    msg = MapiMessage.FromFile(dataDir + "MapiTask.msg");
            MhtSaveOptions opt = SaveOptions.DefaultMhtml;

            opt.MhtFormatOptions = MhtFormatOptions.RenderTaskFields | MhtFormatOptions.WriteHeader;

            opt.FormatTemplates.Clear();
            opt.FormatTemplates.Add(MhtTemplateName.Task.Subject, "<span class='headerLineTitle'>Subject:</span><span class='headerLineText'>{0}</span><br/>");
            opt.FormatTemplates.Add(MhtTemplateName.Task.ActualWork, "<span class='headerLineTitle'>Actual Work:</span><span class='headerLineText'>{0}</span><br/>");
            opt.FormatTemplates.Add(MhtTemplateName.Task.TotalWork, "<span class='headerLineTitle'>Total Work:</span><span class='headerLineText'>{0}</span><br/>");
            opt.FormatTemplates.Add(MhtTemplateName.Task.Status, "<span class='headerLineTitle'>Status:</span><span class='headerLineText'>{0}</span><br/>");
            opt.FormatTemplates.Add(MhtTemplateName.Task.Owner, "<span class='headerLineTitle'>Owner:</span><span class='headerLineText'>{0}</span><br/>");
            opt.FormatTemplates.Add(MhtTemplateName.Task.Priority, "<span class='headerLineTitle'>Priority:</span><span class='headerLineText'>{0}</span><br/>");

            msg.Save(dataDir + "MapiTask_out.mht", opt);
            //ExEnd: ConvertMapiTaskToMHT
        }
Exemple #7
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Email();

            // ExStart:ExportEmailToMHTWithCustomTimezone
            MailMessage eml = MailMessage.Load(dataDir + "Message.eml");

            // Set the local time for message date.
            eml.TimeZoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);

            // or set custom time zone offset for message date (-0800)
            // eml.TimeZoneOffset = new TimeSpan(-8,0,0);

            // The dates will be rendered by local system time zone.
            MhtSaveOptions so = new MhtSaveOptions();

            so.MhtFormatOptions = MhtFormatOptions.WriteHeader;
            eml.Save(dataDir + "ExportEmailToMHTWithCustomTimezone_out.mhtml", so);
            // ExEnd:ExportEmailToMHTWithCustomTimezone
        }
        ///<Summary>
        /// ConvertEMLToMHT method to convert eml to mht
        ///</Summary>

        public Response ConvertEMLToMHT(string fileName, string folderName, string userEmail)
        {
            return(ProcessTask(fileName, folderName, ".mht", false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                // Load mail message
                var mail = MapiHelper.GetMailMessageFromFile(inFilePath);

                // Save as mht with header
                var mhtSaveOptions = new MhtSaveOptions
                {
                    //Specify formatting options required
                    //Here we are specifying to write header informations to output without writing extra print header
                    //and the output headers should display as the original headers in message
                    MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.DisplayAsOutlook,
                    // Check the body encoding for validity.
                    CheckBodyContentEncoding = true
                };

                mail.Save(outPath, mhtSaveOptions);
            }));
        }
Exemple #9
0
        public static void Run()
        {
            //ExStart: RenderingCalendarEvents
            // The path to the File directory.
            string         dataDir  = RunExamples.GetDataDir_Email();
            string         fileName = "Meeting with Recurring Occurrences.msg";
            MailMessage    msg      = MailMessage.Load(dataDir + fileName);
            MhtSaveOptions options  = new MhtSaveOptions();

            {
                options.MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.RenderCalendarEvent;

                //Format the output details if required - optional

                //Set the display for Start Property
                if (options.FormatTemplates.ContainsKey(MhtTemplateName.Start))
                {
                    options.FormatTemplates[MhtTemplateName.Start] = @"<span class='headerLineTitle'>Start:</span><span class='headerLineText'>{0}</span><br/>";
                }
                else
                {
                    options.FormatTemplates.Add(MhtTemplateName.Start, @"<span class='headerLineTitle'>Start:</span><span class='headerLineText'>{0}</span><br/>");
                }

                //Set the display for End Property
                if (options.FormatTemplates.ContainsKey(MhtTemplateName.End))
                {
                    options.FormatTemplates[MhtTemplateName.End] = @"<span class='headerLineTitle'>End:</span><span class='headerLineText'>{0}</span><br/>";
                }
                else
                {
                    options.FormatTemplates.Add(MhtTemplateName.End, @"<span class='headerLineTitle'>End:</span><span class='headerLineText'>{0}</span><br/>");
                }

                //Set the display for Recurrence Property
                if (options.FormatTemplates.ContainsKey(MhtTemplateName.Recurrence))
                {
                    options.FormatTemplates[MhtTemplateName.Recurrence] = @"<span class='headerLineTitle'>Recurrence:</span><span class='headerLineText'>{0}</span><br/>";
                }
                else
                {
                    options.FormatTemplates.Add(MhtTemplateName.Recurrence, @"<span class='headerLineTitle'>Recurrence:</span><span class='headerLineText'>{0}</span><br/>");
                }

                //Set the display for RecurrencePattern Property
                if (options.FormatTemplates.ContainsKey(MhtTemplateName.RecurrencePattern))
                {
                    options.FormatTemplates[MhtTemplateName.RecurrencePattern] = @"<span class='headerLineTitle'>RecurrencePattern:</span><span class='headerLineText'>{0}</span><br/>";
                }
                else
                {
                    options.FormatTemplates.Add(MhtTemplateName.RecurrencePattern, @"<span class='headerLineTitle'>RecurrencePattern:</span><span class='headerLineText'>{0}</span><br/>");
                }

                //Set the display for Organizer Property
                if (options.FormatTemplates.ContainsKey(MhtTemplateName.Organizer))
                {
                    options.FormatTemplates[MhtTemplateName.Organizer] = @"<span class='headerLineTitle'>Organizer:</span><span class='headerLineText'>{0}</span><br/>";
                }
                else
                {
                    options.FormatTemplates.Add(MhtTemplateName.Organizer, @"<span class='headerLineTitle'>Organizer:</span><span class='headerLineText'>{0}</span><br/>");
                }

                //Set the display for RequiredAttendees Property
                if (options.FormatTemplates.ContainsKey(MhtTemplateName.RequiredAttendees))
                {
                    options.FormatTemplates[MhtTemplateName.RequiredAttendees] = @"<span class='headerLineTitle'>RequiredAttendees:</span><span class='headerLineText'>{0}</span><br/>";
                }
                else
                {
                    options.FormatTemplates.Add(MhtTemplateName.RequiredAttendees, @"<span class='headerLineTitle'>RequiredAttendees:</span><span class='headerLineText'>{0}</span><br/>");
                }
            };

            msg.Save(dataDir + "Meeting with Recurring Occurrences.mhtml", options);
            //ExEnd: RenderingCalendarEvents
        }