static void Main(string[] args) { string to, sub, path; to = sub = path = string.Empty; Console.WriteLine("Enter to"); to = Console.ReadLine(); Console.WriteLine("Enter sub"); sub = Console.ReadLine(); Console.WriteLine("Enter path"); path = Console.ReadLine(); Console.WriteLine("Please Wait...."); CreateMessageWithAttachment(path, to, sub); } public static void CreateMessageWithAttachment(string path, string to, string subject) { try { Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem)); #region set email recipients { email.Recipients.Add(to); } #endregion //email subject email.Subject = subject; #region set email Text { // email.Body = body; } #endregion #region email attachment { if (File.Exists(path)) { // int iPosition = (int)email.Body.Length + 1; int iAttachType = (int)Outlook.OlAttachmentType.olByValue; Outlook.Attachment oAttach = email.Attachments.Add(path, iAttachType); } } #endregion email.Display(); } catch (Exception e) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)