GetDataDir_Email() static private méthode

static private GetDataDir_Email ( ) : string
Résultat string
        public static void Run()
        {
            // ExStart:ExtractEmbeddedObjectsFromEmail
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            // Create an instance of MailMessage and load an email file
            MailMessage mailMsg = MailMessage.Load(dataDir + "Message.msg", new MsgLoadOptions());

            foreach (Attachment attachment in mailMsg.Attachments)
            {
                // To display the the attachment file name
                attachment.Save(dataDir + "MessageEmbedded_out.msg");
                Console.WriteLine(attachment.Name);
            }

            mailMsg.From = "*****@*****.**";
            mailMsg.To.Add("*****@*****.**");

            SmtpClient client = new SmtpClient("smtp.server.com")
            {
                Port     = 25,
                Username = "******",
                Password = "******"
            };

            client.Send(dataDir + "Message.msg");
            // ExEnd:ExtractEmbeddedObjectsFromEmail
        }
        public static void SaveAsHtmlWithoutEmbeddingResources()
        {
            string dataDir = RunExamples.GetDataDir_Email();

            //ExStart: SaveAsHtmlWithoutEmbeddingResources
            var fileName = "EmailWithAttandEmbedded.eml";
            var filePath = Path.Combine(dataDir, fileName);

            MailMessage msg         = MailMessage.Load(filePath);
            var         outFileName = Path.Combine(dataDir, fileName + ".html");

            var options = new HtmlSaveOptions()
            {
                EmbedResources      = false,
                SaveResourceHandler =
                    (AttachmentBase attachment, out string resourcePath) =>
                {
                    attachment.Save(Path.Combine(dataDir, attachment.ContentId));
                    resourcePath = Path.Combine(".", attachment.ContentId);
                }
            };

            msg.Save(outFileName, options);
            //ExEnd: SaveAsHtmlWithoutEmbeddingResources
        }
        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 #4
0
        public static void Run()
        {
            // ExStart:DraftAppointmentRequest
            // The path to the File directory.
            string dataDir  = RunExamples.GetDataDir_Email();
            string dstDraft = dataDir + "appointment-draft_out.msg";

            string sender    = "*****@*****.**";
            string recipient = "*****@*****.**";

            MailMessage message = new MailMessage(sender, recipient, string.Empty, string.Empty);

            Appointment app = new Appointment(string.Empty, DateTime.Now, DateTime.Now, sender, recipient)
            {
                MethodType = AppointmentMethodType.Publish
            };

            message.AddAlternateView(app.RequestApointment());

            MapiMessage msg = MapiMessage.FromMailMessage(message);

            // Save the appointment as draft.
            msg.Save(dstDraft);

            Console.WriteLine(Environment.NewLine + "Draft saved at " + dstDraft);
            // ExEnd:DraftAppointmentRequest
        }
Exemple #5
0
        public static void Run()
        {
            // ExStart:CreatingTNEFFromMSG
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            // Create an instance of MailMessage and load an email file
            MailMessage mailMsg = MailMessage.Load(dataDir + "EmailWithAttandEmbedded.eml");

            // Extract Attachments from the message
            foreach (Attachment attachment in mailMsg.Attachments)
            {
                // To display the the attachment file name
                Console.WriteLine(attachment.Name);

                // Save the attachment to disc
                attachment.Save(attachment.Name);

                // You can also save the attachment to memory stream
                MemoryStream ms = new MemoryStream();

                attachment.Save(ms);
            }

            // Extract Inline images from the message
            foreach (LinkedResource lr in mailMsg.LinkedResources)
            {
                Console.WriteLine(lr.ContentType.Name);

                lr.Save(lr.ContentType.Name);
            }
        }
        public static void Run()
        {
            // ExStart:ManagingEmailAttachments
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            // Create an instance of MailMessage class
            MailMessage message = new MailMessage {
                From = "*****@*****.**"
            };

            message.To.Add("*****@*****.**");

            // Load an attachment
            Attachment attachment = new Attachment(dataDir + "1.txt");

            // Add Multiple Attachment in instance of MailMessage class and Save message to disk
            message.Attachments.Add(attachment);
            message.AddAttachment(new Attachment(dataDir + "1.jpg"));
            message.AddAttachment(new Attachment(dataDir + "1.doc"));
            message.AddAttachment(new Attachment(dataDir + "1.rar"));
            message.AddAttachment(new Attachment(dataDir + "1.pdf"));
            message.Save(dataDir + "outputAttachments_out.msg", SaveOptions.DefaultMsgUnicode);
            // ExEnd:ManagingEmailAttachments
        }
        public static void Run()
        {
            // The path to the File directory.
            string dataDir  = RunExamples.GetDataDir_Email();
            string dstEmail = dataDir + "New-Draft.msg";

            // Create a new instance of MailMessage class
            MailMessage message = new MailMessage();

            // Set sender information
            message.From = "*****@*****.**";

            // Add recipients
            message.To.Add("*****@*****.**");
            message.To.Add("*****@*****.**");

            // Set subject of the message
            message.Subject = "New message created by Aspose.Email";

            // Set Html body of the message
            message.IsBodyHtml = true;
            message.HtmlBody   = "<b>This line is in bold.</b> <br/> <br/><font color=blue>This line is in blue color</font>";

            // Create an instance of MapiMessage and load the MailMessag instance into it
            MapiMessage mapiMsg = MapiMessage.FromMailMessage(message);

            // Set the MapiMessageFlags as UNSENT and FROMME
            mapiMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_FROMME);

            // Save the MapiMessage to disk
            mapiMsg.Save(dstEmail);

            Console.WriteLine(Environment.NewLine + "Created draft MSG at " + dstEmail);
        }
        public static void Run()
        {
            // ExStart:LoadMessageWithLoadOptions
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            // Load Eml, html, mhtml, msg and dat file
            MailMessage mailMessage = MailMessage.Load(dataDir + "Message.eml", new EmlLoadOptions());

            MailMessage.Load(dataDir + "description.html", new HtmlLoadOptions());
            MailMessage.Load(dataDir + "Message.mhtml", new MhtmlLoadOptions());
            MailMessage.Load(dataDir + "Message.msg", new MsgLoadOptions());

            // loading with custom options
            EmlLoadOptions emlLoadOptions = new EmlLoadOptions
            {
                PrefferedTextEncoding   = Encoding.UTF8,
                PreserveTnefAttachments = true
            };

            MailMessage.Load(dataDir + "description.html", emlLoadOptions);
            HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions
            {
                PrefferedTextEncoding  = Encoding.UTF8,
                ShouldAddPlainTextView = true,
                PathToResources        = dataDir
            };

            MailMessage.Load(dataDir + "description.html", emlLoadOptions);
            // ExEnd:LoadMessageWithLoadOptions
        }
        public static void Run()
        {
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            // ExStart:MailMessageFeatures
            // Create a new message
            MailMessage message = new MailMessage();

            message.From    = "*****@*****.**";
            message.To      = "*****@*****.**";
            message.Subject = "Using MailMessage Features";

            // Specify message date
            message.Date = DateTime.Now;

            // Specify message priority
            message.Priority = MailPriority.High;

            // Specify message sensitivity
            message.Sensitivity = MailSensitivity.Normal;

            // Specify options for delivery notifications
            message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
            // ExEnd:MailMessageFeatures

            message.Save(dataDir + "UseMailMessageFeatures_out.eml", SaveOptions.DefaultEml);
        }
        public static void Run()
        {
            // ExStart:EmbeddedObjects
            // The path to the File directory.
            string dataDir  = RunExamples.GetDataDir_Email();
            string dstEmail = dataDir + "EmbeddedImage.msg";

            // Create an instance of the MailMessage class and Set the addresses and Set the content
            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("*****@*****.**");
            mail.To.Add("*****@*****.**");
            mail.Subject = "This is an email";

            // Create the plain text part It is viewable by those clients that don't support HTML
            AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content", null, "text/plain");

            /* Create the HTML part.To embed images, we need to use the prefix 'cid' in the img src value.
             * The cid value will map to the Content-Id of a Linked resource. Thus <img src='cid:barcode'> will map to a LinkedResource with a ContentId of //'barcode'. */
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:barcode>", null, "text/html");

            // Create the LinkedResource (embedded image) and Add the LinkedResource to the appropriate view
            LinkedResource barcode = new LinkedResource(dataDir + "1.jpg", MediaTypeNames.Image.Jpeg)
            {
                ContentId = "barcode"
            };

            mail.LinkedResources.Add(barcode);
            mail.AlternateViews.Add(plainView);
            mail.AlternateViews.Add(htmlView);
            mail.Save(dataDir + "EmbeddedImage_out.msg", SaveOptions.DefaultMsgUnicode);
            // ExEnd:EmbeddedObjects
            Console.WriteLine(Environment.NewLine + "Message saved with embedded objects successfully at " + dstEmail);
        }
Exemple #11
0
        public static void Run()
        {
            // ExStart:PrintHeaderUsingMhtFormatOptions
            // The path to the File directory.
            string              dataDir       = RunExamples.GetDataDir_Email();
            const string        pageHeader    = @"<div><div class='pageHeader'>&quot;Panditharatne, Mithra&quot; &lt;[email protected]&gt;<hr/></div>";
            MailMessage         message       = MailMessage.Load(dataDir + "Message.eml");
            MhtMessageFormatter mailFormatter = new MhtMessageFormatter();
            MailMessage         copyMessage   = message.Clone();

            mailFormatter.Format(copyMessage);
            Console.WriteLine(copyMessage.HtmlBody.Contains(pageHeader) ? "True" : "False");
            MhtFormatOptions options = MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.WriteCompleteEmailAddress;

            mailFormatter.Format(message, options);
            if (!message.HtmlBody.Contains(pageHeader))
            {
                Console.WriteLine("True");
            }
            else
            {
                Console.WriteLine("False");
            }
            // ExEnd:PrintHeaderUsingMhtFormatOptions
        }
Exemple #12
0
        public static void Run()
        {
            // The path to the File directory.
            string dataDir  = RunExamples.GetDataDir_Email();
            string dstEmail = dataDir + "test.eml";

            // Create a new instance of MailMessage class
            MailMessage message = new MailMessage();

            // Set subject of the message
            message.Subject = "New message created by Aspose.Email for .NET";

            // Set Html body
            message.IsBodyHtml = true;
            message.HtmlBody   = "<b>This line is in bold.</b> <br/> <br/><font color=blue>This line is in blue color</font>";

            // Set sender information
            message.From = "*****@*****.**";

            // Add TO recipients
            message.To.Add("*****@*****.**");
            message.To.Add("*****@*****.**");

            // Add CC recipients
            message.CC.Add("*****@*****.**");
            message.CC.Add("*****@*****.**");

            // Save message in EML, MSG and MHTML formats
            message.Save(dataDir + "Message.eml", Aspose.Email.Mail.SaveOptions.DefaultEml);
            message.Save(dataDir + "Message.msg", Aspose.Email.Mail.SaveOptions.DefaultMsgUnicode);
            message.Save(dataDir + "Message.mhtml", Aspose.Email.Mail.SaveOptions.DefaultMhtml);

            Console.WriteLine(Environment.NewLine + "Created new email in EML, MSG and MHTML formats successfully.");
        }
Exemple #13
0
        public static void Run()
        {
            // ExStart:CreateNewMailMessage
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            // Create a new instance of MailMessage class
            MailMessage message = new MailMessage();

            // Set subject of the message, Html body and sender information
            message.Subject  = "New message created by Aspose.Email for .NET";
            message.HtmlBody = "<b>This line is in bold.</b> <br/> <br/>" + "<font color=blue>This line is in blue color</font>";
            message.From     = new MailAddress("*****@*****.**", "Sender Name", false);

            // Add TO recipients and Add CC recipients
            message.To.Add(new MailAddress("*****@*****.**", "Recipient 1", false));
            message.To.Add(new MailAddress("*****@*****.**", "Recipient 2", false));
            message.CC.Add(new MailAddress("*****@*****.**", "Recipient 3", false));
            message.CC.Add(new MailAddress("*****@*****.**", "Recipient 4", false));

            // Save message in EML, EMLX, MSG and MHTML formats
            message.Save(dataDir + "Message_out.eml", SaveOptions.DefaultEml);
            message.Save(dataDir + "Message_out.emlx", SaveOptions.CreateSaveOptions(MailMessageSaveType.EmlxFormat));
            message.Save(dataDir + "Message_out.msg", SaveOptions.DefaultMsgUnicode);
            message.Save(dataDir + "Message_out.mhtml", SaveOptions.DefaultMhtml);
            // ExEnd:CreateNewMailMessage
        }
Exemple #14
0
        public static void Run()
        {
            // ExStart:DetectTNEFMessage
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email() + "Message.eml";

            MailMessage mail   = MailMessage.Load(dataDir);
            bool        isTnef = mail.OriginalIsTnef;
            // ExEnd:DetectTNEFMessage
        }
Exemple #15
0
        public static void Run()
        {
            // ExStart:ExportEmailToEML
            string dataDir = RunExamples.GetDataDir_Email();

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

            msg.Save(dataDir + "ExporttoEml_out.eml", SaveOptions.DefaultEml);
            // ExEnd:ExportEmailToEML
        }
Exemple #16
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Email();

            // ExStart:SaveMailMessageAsMHTML
            // Initialize and Load an existing EML file by specifying the MessageFormat
            MailMessage eml = MailMessage.Load(dataDir + "Message.eml");

            eml.Save(dataDir + "AnEmail_out.mthml", SaveOptions.DefaultMhtml);
            // ExEnd:SaveMailMessageAsMHTML
        }
        public static void Run()
        {
            String dataDir = RunExamples.GetDataDir_Email();

            // ExStart:GetDecodedHeaderValue
            MailMessage mailMessage  = MailMessage.Load(dataDir + "emlWithHeaders.eml");
            string      decodedValue = mailMessage.Headers.GetDecodedValue("Thread-Topic");

            Console.WriteLine(decodedValue);
            // ExEnd:GetDecodedHeaderValue
        }
Exemple #18
0
        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
        }
Exemple #19
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Email();

            // ExStart:DetectMessageIsTNEF
            MailMessage mail = MailMessage.Load(dataDir + "tnefEml1.eml");

            bool isTnef = mail.OriginalIsTnef;

            Console.WriteLine("Is input EML originally TNEF? {0}", isTnef.ToString());
            // ExEnd:DetectMessageIsTNEF
        }
        public static void Run()
        {
            // ExStart:LoadAndSaveFileAsEML
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            // Initialize and Load an existing EML file by specifying the MessageFormat
            MailMessage mailMessage = MailMessage.Load(dataDir + "Attachments.eml");

            mailMessage.Save(dataDir + "LoadAndSaveFileAsEML_out.eml", SaveOptions.DefaultEml);
            // ExEnd:LoadAndSaveFileAsEML
        }
        public static void Run()
        {
            String dataDir = RunExamples.GetDataDir_Email();

            // ExStart:RetrieveContentDescriptionFromAttachment
            MailMessage message = MailMessage.Load(dataDir + "EmailWithAttandEmbedded.eml");

            string description = message.Attachments[0].Headers["Content-Description"];

            Console.WriteLine(description);
            // ExEnd:RetrieveContentDescriptionFromAttachment
        }
Exemple #22
0
        public static void Run()
        {
            // ExStart:DetectDifferentFileFormats
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            // Detect file format and Gets the detected load format
            FileFormatInfo info = FileFormatUtil.DetectFileFormat(dataDir + "message.msg");

            Console.WriteLine("The message format is: " + info.FileFormatType);
            // ExEnd:DetectDifferentFileFormats
        }
        public static void Run()
        {
            // ExStart:DetermineAttachmentEmbeddedMessage
            string      dataDir = RunExamples.GetDataDir_Email() + "EmailWithAttandEmbedded.eml";
            MailMessage eml     = MailMessage.Load(dataDir);

            if (eml.Attachments[0].IsEmbeddedMessage)
            {
                Console.WriteLine("Attachment is an embedded message");
            }
            // ExEnd:DetermineAttachmentEmbeddedMessage
        }
 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
 }
Exemple #25
0
        public static void Run()
        {
            // ExStart:LoadingEMLAndSavingToMSG
            // Data directory for reading and writing files
            string dataDir = RunExamples.GetDataDir_Email();

            // Initialize and Load an existing EML file by specifying the MessageFormat
            MailMessage eml = MailMessage.Load(dataDir + "Message.eml");

            // Save the Email message to disk in ASCII format and Unicode format
            eml.Save(dataDir + "AnEmail_out.msg", SaveOptions.DefaultMsgUnicode);
            // ExEnd:LoadingEMLAndSavingToMSG
        }
        public static void Run()
        {
            string      dataDir = RunExamples.GetDataDir_Email();
            MailMessage message = MailMessage.Load(dataDir + "Attachments.eml");

            // ExStart:DisplayAttachmentFileName
            // Create a loop to display the no. of attachments present in email message
            foreach (Attachment attachment in message.Attachments)
            {
                // Display the the attachment file name
                Console.WriteLine(attachment.Name);
            }
            // ExEnd:DisplayAttachmentFileName
        }
Exemple #27
0
        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
        }
Exemple #28
0
        public static void Run()
        {
            //ExStart: PreserveEmbeddedMSGFormatDuringLoad
            string dataDir = RunExamples.GetDataDir_Email();

            MailMessage mail = MailMessage.Load(dataDir + "tnefWithMsgInside.eml", new EmlLoadOptions()
            {
                PreserveEmbeddedMessageFormat = true
            });

            FileFormatType fileFormat = FileFormatUtil.DetectFileFormat(mail.Attachments[0].ContentStream).FileFormatType;

            Console.WriteLine("Embedded message file format: " + fileFormat);
            //ExEnd: PreserveEmbeddedMSGFormatDuringLoad
        }
Exemple #29
0
        public static void Run()
        {
            // ExStart:1
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            MailMessage mail = MailMessage.Load(dataDir + "HtmlWithUrlSample.eml");

            string body_with_url    = mail.GetHtmlBodyText(true);  // body will contain URL
            string body_without_url = mail.GetHtmlBodyText(false); // body will not contain URL

            Console.WriteLine("Body with URL: " + body_with_url);
            Console.WriteLine("Body without URL: " + body_without_url);
            // ExEnd:1
        }
        public static void Run()
        {
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Email();

            // Create an instance of MailMessage and load an email file
            MailMessage mailMsg = MailMessage.Load(dataDir + "Test.eml", new EmlLoadOptions());

            foreach (Attachment attachment in mailMsg.Attachments)
            {
                // To display the the attachment file name
                attachment.Save(dataDir + "ExtractAttachments_out." + attachment.Name);
                Console.WriteLine(attachment.Name);
            }
        }