Aspose.Email.Examples.CSharp.Email.ExtractEmbeddedObjectsFromEmail.Run C# (CSharp) Method

Run() public static method

public static Run ( ) : void
return void
        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 = "[email protected]";
            mailMsg.To.Add("[email protected]");

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

            try
            {
                client.Send(dataDir + "Message.msg");
            }
            catch (Exception ex)
            {
                
               Console.Write(ex.Message);
            }
          
            // ExEnd:ExtractEmbeddedObjectsFromEmail
        }
    }
ExtractEmbeddedObjectsFromEmail