使用带有HTML体的C#创建Outlook文件可以通过以下步骤实现:
using Outlook = Microsoft.Office.Interop.Outlook;
Outlook.Application outlookApp = new Outlook.Application();
Outlook.NameSpace outlookNamespace = outlookApp.GetNamespace("MAPI");
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "邮件主题";
mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mailItem.HTMLBody = "<html><body><h1>这是HTML正文</h1></body></html>";
Outlook.Recipient recipient = mailItem.Recipients.Add("收件人邮箱地址");
recipient.Resolve();
mailItem.Attachments.Add("附件路径", Outlook.OlAttachmentType.olByValue, 1, "附件名称");
mailItem.Display();
mailItem.Send();
完整的代码示例:
using Outlook = Microsoft.Office.Interop.Outlook;
Outlook.Application outlookApp = new Outlook.Application();
Outlook.NameSpace outlookNamespace = outlookApp.GetNamespace("MAPI");
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "邮件主题";
mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mailItem.HTMLBody = "<html><body><h1>这是HTML正文</h1></body></html>";
Outlook.Recipient recipient = mailItem.Recipients.Add("收件人邮箱地址");
recipient.Resolve();
mailItem.Attachments.Add("附件路径", Outlook.OlAttachmentType.olByValue, 1, "附件名称");
mailItem.Display();
mailItem.Send();
这样就可以使用带有HTML体的C#代码创建Outlook文件,并发送带有HTML内容的邮件。请注意,这里的代码示例仅适用于使用Microsoft Office安装的Outlook客户端。
领取专属 10元无门槛券
手把手带您无忧上云