Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate an e-mail to be downloaded by client and sent from their outlook account

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.

like image 717
Jason Summers Avatar asked Jul 13 '10 17:07

Jason Summers


2 Answers

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

like image 182
bruceboughton Avatar answered Oct 05 '22 23:10

bruceboughton


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.

like image 26
Gage Avatar answered Oct 06 '22 01:10

Gage