生成一封电子邮件供客户下载并从其 Outlook 帐户发送

发布于 2024-09-09 03:42:25 字数 292 浏览 3 评论 0原文

我正在开发的应用程序的要求之一是让用户能够向我们的服务台提交致命错误的调试报告(很像 Windows 错误报告)。

有人告诉我,电子邮件必须来自客户的邮件帐户,以防止帮助台收到垃圾邮件并引发大量重复呼叫。

为了实现这一目标,我尝试在服务器上编写一封邮件消息,在正文中为帮助台提供一条不错的消息,并将错误报告作为附件,然后将其添加到响应中,以便用户可以下载,打开并发送。

我尝试过使用 Outlook 互操作性组件,但没有成功,这是一个有争议的问题,因为我在过去 6 小时的谷歌搜索中发现,创建多个应用程序实例非常消耗资源。

One of the requirements for the application that I'm working on is to enable users to submit a debugging report to our helpdesk for fatal errors (much like windows error reporting).

I've been told that e-mails must come from a client's mail account to prevent the helpdesk getting spammed and loads of duplicate calls raised.

In order to achieve this, I'm trying to compose a mail message on the server, complete with a nice message in the body for the helpdesk and the error report as an attachment, then add it to the Response so that the user can download, open and send it.

I've tried, without success, to make use of the Outlook Interoperability Component which is a moot point because I've discovered in the last 6 hours of googling that creating more than a few Application instances is very resource intensive.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜清冷一曲。 2024-09-16 03:42:25

如果您希望用户在客户端发送电子邮件,我不知道 System.Net.Mail 将如何帮助您。

您有两个选项:

  1. mailto:[电子邮件受保护]?subject=Error&body=此处错误消息...

  2. 让用户以某种格式下载电子邮件,在客户端中打开它,然后发送

选项 1 可能会因复杂的正文而崩溃。使用选项 2,您需要找到所有邮件客户端(您的用户使用的)都支持的格式。

使用选项 1,您可以根据某些错误 ID 将电子邮件详细信息存储在本地服务器上,然后仅发送主题中包含错误 ID 的电子邮件:

mailto:[电子邮件受保护]?subject=遇到错误 987771

If you want the user to send an email client side, I don't see how System.Net.Mail will help you.

You have two options:

  1. mailto:[email protected]?subject=Error&body=Error message here...

  2. get user to download email in some format, open it in their client and send it

Option 1 will probably break down with complex bodies. With Option 2, you need to find a format that is supported by all mail clients (that your users use).

With option 1, you could store the email details locally on your server against some Error ID and just send the email with an Error ID in the subject:

mailto:[email protected]?subject=Error 987771 encountered

乖乖哒 2024-09-16 03:42:25

在我们的一个应用程序中,用户点击生成按钮,它会在 Outlook 中创建并打开电子邮件。他们所要做的就是点击发送按钮。功能如下。

public static void generateEmail(string emailTo, string ccTo, string subject, string body, bool bcc)
        {
            Outlook.Application objOutlook = new Outlook.Application();
            Outlook.MailItem mailItem = (Outlook.MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));

            /* Sets the recipient e-mails to be either sent by 'To:' or 'BCC:' 
             * depending on the boolean called 'bcc' passed. */
            if (!(bcc))
            {
                mailItem.To = emailTo;
            }
            else
            {
                mailItem.BCC = emailTo;
            }
            mailItem.CC = ccTo;
            mailItem.Subject = subject;
            mailItem.Body = body;
            mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
            mailItem.Display(mailItem);
        }

正如您所看到的,它目前正在以纯文本形式输出电子邮件,因为它需要黑莓友好。如果您需要一些格式选项,您可以轻松地将格式更改为 HTML 或 Richtext。对于 HTML,请使用 mailItem.HTMLBody

希望这会有所帮助。

编辑:

我应该注意,这是在 C# 应用程序中使用的,并且它引用 Microsoft.Office.Core 并在该函数所在的电子邮件类中使用 Outlook

In one of our applications the user hits the generate button and it creates and opens the email in outlook. All they have to do is hit the send button. The functions is below.

public static void generateEmail(string emailTo, string ccTo, string subject, string body, bool bcc)
        {
            Outlook.Application objOutlook = new Outlook.Application();
            Outlook.MailItem mailItem = (Outlook.MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));

            /* Sets the recipient e-mails to be either sent by 'To:' or 'BCC:' 
             * depending on the boolean called 'bcc' passed. */
            if (!(bcc))
            {
                mailItem.To = emailTo;
            }
            else
            {
                mailItem.BCC = emailTo;
            }
            mailItem.CC = ccTo;
            mailItem.Subject = subject;
            mailItem.Body = body;
            mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
            mailItem.Display(mailItem);
        }

As you can see it is outputting the email in plaintext at the moment because it was required to be blackberry friendly. You can easily change the format to HTML or richtext if you want some formatting options. For HTML use mailItem.HTMLBody

Hope this helps.

EDIT:

I should note that this is used in a C# Application and that it is referencing Microsoft.Office.Core and using Outlook in the Email class the function is located in.

念﹏祤嫣 2024-09-16 03:42:25

简单的答案是,您想要实现的目标实际上在所有平台和邮件客户端上都无法实现。当被要求做不可能的事情时,明智的做法是想出一个替代方案并提出建议。

假设您的故障报告只能从错误页面访问,那么您已经对垃圾邮件设置了屏障 - 除非垃圾邮件发送者可以强制例外。

我总是通过将故障和文本记录到数据库中并将其与票务系统集成来处理此问题。也许还有一个 mailto: 正如 Bruce 建议的 subject=ID&body=text 以允许用户通过电子邮件发送内容。

我认为 .eml 格式文件也没有帮助 - 因为他们需要转发它,并且大多数用户可能会感到困惑。

.eml 实际上是消息的纯文本,包括符合 RFC-5322 的标头。

The simple answer is that what you are trying to achieve isn't realistically achievable across all platforms and mail clients. When asked to do the improbable it is wise to come up with an alternative and suggest that.

Assuming that your fault report is only accessible from an error page then you've already got a barrier to spam - unless the spammers can force an exception.

I've always handled this by logging the fault and text into the database and integrating that with a ticketing system. Maybe also have a mailto: as Bruce suggest with subject=ID&body=text to allow the user to send something by email.

I don't think an .eml format file will help either - because they'll need to forward it, and most users would probably get confused.

A .eml is effectively plain text of the message including headers as per RFC-5322.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文