5

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Jason Summers
  • 307
  • 3
  • 13
  • Have you tried having them download a .eml file and open it with Outlook? – Borealid Jul 13 '10 at 18:03
  • Have you tried `System.Net.Mail` with impersonation enabled? You could try http://stackoverflow.com/questions/1448019/send-email-from-outlook-express-in-c – Jaroslav Jandek Jul 13 '10 at 18:04
  • @Borealid - I've not tried a .eml file. Basically, as long as opens in Outlook I'm not bothered. @Jaroslav I've managed to get as far as constructing the message using System.Net.Mail the problem I'm facing is how to convert that into a downloadable file – Jason Summers Jul 13 '10 at 18:08
  • I know this is old but It was a top search result for me on google. This looks like an answer: http://stackoverflow.com/a/1264724/959977 – OrangeKing89 Nov 18 '15 at 13:46

3 Answers3

4

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:support@domain.com?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:support@domain.com?subject=Error 987771 encountered

bruceboughton
  • 622
  • 5
  • 16
  • Thanks for your input Bruce. I had previously tried using a mailto link but as you quite rightly point out, it very quickly breaks when I try and add things like a Stack Trace. Plus in IE8, there is apparrently a 512 character limit on mailto links. I'm trying to achieve option 2 as described in my original question, for no other reason than it is a requirement due to the way our helpdesk operates. – Jason Summers Jul 13 '10 at 18:24
2

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.

Richard Harrison
  • 19,247
  • 4
  • 40
  • 67
2

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.

Community
  • 1
  • 1
Gage
  • 7,365
  • 9
  • 47
  • 77
  • 1
    Surely this is in a client side application rather than an ASP.NET application as in the question? – bruceboughton Jul 14 '10 at 12:35
  • This was very helpful for me, but first I had to install the Office development tools ( in VS: Tools in menu bar => Get Tools and Features). Then, to reference Outlook as Gage mentioned above, you need to add `using Outlook = Microsoft.Office.Interop.Outlook;` to the top of the class. – Synctrex Aug 29 '18 at 20:28