Wednesday, September 30, 2009

Open Outlook with New email - Console Application

Although there are some methodes in System.Web.Mail namespace for sending email , but sometimes customers like to open outlook automatically with a new mail inside and let user to complete the mail before sending, here I write a sample console application to do it,

note: add outlook com reference manually to your project.

using System;
using  System.Collections.Generic;
using  System.Text;
using  System.Diagnostics;
using  Outlook = Microsoft.Office.Interop.Outlook;

namespace Openoutlook
class Program
static void Main(string[] args)
Application objOutlk = new Outlook.Application();
object objMail = new object();
MailItem mic = (Outlook.MailItem)(objOutlk.CreateItem(Outlook.OlItemType.olMailItem));
//mic.To = //toTextBox.Text;
//mic.CC = ccTextBox.Text;
//mic.BCC = bccTextBox.Text;
mic.Subject ="Test Subject";// subjectTextBox.Text;
mic.Importance = Outlook.

// mic.HTMLBody = sb.ToString();
// Adds Attachment to the Mail Message.

// All you need to do is to declare this relative to the number of attachments you have.
mic.Attachments.Add( @"C:\temp\1.txt", Outlook.OlAttachmentType.olByValue, 1, "Attachment Name");
mic.Attachments.Add( @"C:\temp\2.txt", Outlook.OlAttachmentType.olByValue, 1, "Attachment Name");
//Open outlook and display new msg mail


I did not fill all field such as body , To or CC , you can fill the by your self.

No comments:

Post a Comment

Thank you for sharing your knowledge and experiences with this weblog.