【发布时间】:2020-10-12 23:00:32
【问题描述】:
我有一个需求,我需要从 SQL DB 获取数据并将该内容查看/下载到 Microsoft Outlook。 DB Table 包含各种列,例如 Id、Content、Subject、ToAddress 和其他常规信息。此表中的内容列是 HTML 格式。
我在我的应用程序中使用 Angular 6 和 Wep API。
我尝试了多种方法,但都没有解决我的问题:
方法一:
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = message.Subject;
mailItem.To = message.ToEmailAddress;
mailItem.HTMLBody = message.Content;
mailItem.Importance = Outlook.OlImportance.olImportanceLow;
mailItem.Display(true);
为此,电子邮件在服务器计算机上打开,但不在客户端计算机上。
方法二:
mailto:stuff@things.com&subject=something&body=<doctype html><span style="color:red">Hi how are you</span>
我不能使用这种方法,因为它不处理电子邮件正文中的 HTML。我正在为电子邮件正文使用内容数据。
内容列中的示例数据:
<style type="text/css">
html {
font-family: Arimo, sans-serif, Calibri (Body);
}
body {
font-family: Arimo, sans-serif, Calibri (Body);
}
label {
font-weight: normal !important;
}
p, div {
font-family: Arimo, sans-serif, Calibri (Body);
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
font-family: Arimo, sans-serif, Calibri (Body);
}
footer {
font-family: Arimo, sans-serif, Calibri (Body);
}
</style>
<html>
<body>
<p>Hello</p>
<p>Thank you for using the application</p>
<p>
https://www.google.com
</p>
<p>
This is another paragraph
<br /><br />
Thank you,
<br />
Your DEV Team
</p>
</body>
<footer>
<span style="font-size:x-small;font-style: italic;color:#2b568f">
Note: Please do not reply to this email.
</span>
</footer>
</html>
提前致谢
【问题讨论】:
-
您无法通过 Web API c# 代码在客户端计算机上打开 Outlook。您需要从在客户端浏览器上运行的 Angular 执行此操作。您首先从 Web API 获取数据到 Angular,然后从 Angular 打开邮件客户端。 stackoverflow.com/questions/36553390/…
-
@ChetanRanpariya 是的,我也尝试过这种方法。问题是我的数据库中的数据以 HTML 格式存储,当我将数据分配给正文时,它被视为纯文本并在电子邮件正文中显示 HTML 代码。
-
无法为 mailto 设置 html 正文。你可以在这里阅读stackoverflow.com/questions/5620324/mailto-link-with-html-body。您希望用户使用电子邮件正文打开电子邮件客户端,以便用户只需单击发送按钮即可发送电子邮件?
-
是的,如果用户愿意,他们应该能够发送电子邮件。
-
hmm...正如我之前所说,为mailto 设置html 正文是不可能的。您可能希望提供在 html 页面中显示内容并允许用户复制它的功能,以便用户可以将其复制并粘贴到他们的电子邮件客户端并手动发送电子邮件...