views:

64

answers:

3

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.

+3  A: 

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

bruceboughton
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
+2  A: 

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
+1  A: 

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.

Gage
Surely this is in a client side application rather than an ASP.NET application as in the question?
bruceboughton
Read the edit...
Gage