using Outlook = Microsoft.Office.Interop.Outlook; |
|
using (Outlook.Application olApp = new Outlook.Application()) |
{ |
using (Outlook.MailItem mailItem = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem)) |
{ |
mailItem.To = "xyz@company.com" ; |
mailItem.Subject = "A test" ; |
mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML; |
mailItem.HTMLBody = "Hello world" ; |
|
//now attached the file |
int attachPos = ( int )mailItem.Body.Length + 1; |
int attachType = ( int )Outlook.OlAttachmentType.olByValue; |
mailItem.Attachments.Add( @"C:\\hello.txt" , attachType, attachPos, attachName); |
|
((Outlook._MailItem)mailItem).Send(); |
MessageBox.Show( "Mail has been sent successfully!" ); |
} |
} |