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:SavingMSGWithPreservedDates // 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 as msg with preserved dates MsgSaveOptions msgSaveOptions = new MsgSaveOptions(MailMessageSaveType.OutlookMessageFormatUnicode) { PreserveOriginalDates = true }; eml.Save(Path.Combine(dataDir, "outTest_out.msg"), msgSaveOptions); // ExEnd:SavingMSGWithPreservedDates }
static void Run() { // ExStart: SaveMessageAsOFT /// <summary> /// This exmpale shows how to save an email as Outlook Template (.OFT) file using the MailMesasge API /// MsgSaveOptions.SaveAsTemplate - Set to true, if need to be saved as Outlook File Template(OFT format). /// Available from Aspose.Email for .NET 6.4.0 onwards /// </summary> using (MailMessage eml = new MailMessage("*****@*****.**", "*****@*****.**", "template subject", "Template body")) { string oftEmlFileName = "EmlAsOft.oft"; MsgSaveOptions options = SaveOptions.DefaultMsgUnicode; options.SaveAsTemplate = true; eml.Save(oftEmlFileName, options); } // ExEnd: SaveMessageAsOFT }