读取.html或.rtf并将其用作Mail.Body

本文关键字:Mail Body html rtf 读取 | 更新日期: 2023-09-27 18:06:15

        string Mailto = "username@domainname";
        string MailCc = "username@domainname";
        string Subject = "Test";
        ReadSignature();
        Outlook.Application app = new Outlook.Application();
        Outlook.MailItem mail = (Outlook.MailItem)app.CreateItem(Outlook.OlItemType.olMailItem);
        mail.To = Mailto;
        mail.CC = MailCc;
        mail.Subject = Subject;
        mail.HTMLBody = "<html><body>This just a test</body></html>" + signature;
        mail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
        mail.Display(true);

我想在按钮点击上打开邮件,如上所示。完美的工作。不,我想弄清楚如何读取文件并将其用作正文。

背景:我想有像4个不同的邮件,都格式化好。我想我可以把这些文件写成。rtf。doc。msg之类的文件然后把这些文件复制到mail。htmlbody。

读取.html或.rtf并将其用作Mail.Body

好的。其实很简单;-)

        //Local File
        String htmlCode = File.ReadAllText(@"C:'Test.html", Encoding.Default);
        //Webfile
        WebClient client = new WebClient();
        String htmlCode = client.DownloadString(@"http://www.google.com");
        mail.HTMLBody = htmlCode + signature;