I want to open Outlook from my .net application with attachment.
I am using the following codes and its sending mails properly.
But its attaching the file in mail body area instead of attachment field of outlook. I want to attach the file in attachment textbox of outlook. Can anyone help me please.
| Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add("e-mail address"); oRecip.Resolve(); oMsg.Subject = ""; oMsg.Body = ""; String sSource = "C:\\test.txt"; String sDisplayName = "MyFirstAttachment"; int iPosition = (int)oMsg.Body.Length + 1; int iAttachType = (int)Outlook.OlAttachmentType.olByValue; Outlook.Attachment oAttach = oMsg.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName); oMsg.Display(true); |
Regards,
B
Muhammad usmanPosted Sep 24, 2010, 5:14 AM
Hirendra SisodiyaPosted Sep 21, 2010, 8:54 AM
try this code:
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oMsg.Recipients.Add("e-mail address");
oRecip.Resolve();
oMsg.Subject = "";
oMsg.Body = "";
String sSource = "C:\\cmd.txt";
String sDisplayName = "MyFirstAttachment";
oMsg.Attachments.Add(sSource, 1, 1, sDisplayName);
oMsg.Display(true);
thanks
Please mark as answer if it helps