0

I have been following the example below to send email using C# code with success: MSDN Mail Message

However, I would like the code to display the composed email message on user machine, so that user can have a final check before hitting send button on outlook.

In the VBA world, I can use mail.Display in place of mail.Send. Can anyone provide some advice to achieve that in C#?

Thanks.

Danielle
  • 317
  • 2
  • 10

2 Answers2

1

How about this...

private void btnEmail_Click(object sender, EventArgs e)  
{ 
   string command = "mailto:somebody@domain.com?subject=The Subject&bcc=another@codegaim.com&body=Hi,I found this website and thought you might like it http://www.geocities.com/wowhtml/";  
   Process.Start(command); 
}
Mick
  • 6,527
  • 4
  • 52
  • 67
  • Thanks Mick, my email message is in HTML form. How do I use this? – Danielle Aug 25 '14 at 07:00
  • You would have to encode the html... could get tricky, but HttpServerUtility.UrlEncode might do it for you... http://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.110).aspx – Mick Aug 25 '14 at 07:01
0

Found a great solution to my problem i.e. to use Microsoft Office Interop Outlook instead of System.Net.MailMessage

followed this: How to send a mail using Microsoft.Office.Interop.Outlook.MailItem by specifying the From Address

//using Microsoft.Office.Interop.Outlook;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Outlook;


namespace ConsoleApplication1
{

    using Outlook = Microsoft.Office.Interop.Outlook; 

    public static class Program
    {
        static void Main(string[] args)
        {

            SendUsingAccountExample();
        }


        private static void SendUsingAccountExample()
        {
            var application = new Application();
            var mail = (_MailItem)application.CreateItem(OlItemType.olMailItem);
            mail.Body = "Hello";
            mail.Subject = "Good Bye";
            mail.To = "hello@google.com";
            // Next 2 lines are optional. if not specified, the default account will be used
            Outlook.Account account = Application.Session.Accounts["MyOtherAccount"];
            mail.SendUsingAccount = account;


            mail.Display(false); // To Display
            //mail.Send(); // To Send

        }

    }
}
Community
  • 1
  • 1
Danielle
  • 317
  • 2
  • 10