Reputation: 711
i want to write application who send email using outlook and i found this link. i try this and it's perfect for me but the only thing that i miss here is the option to attach files to the mail, is it possible to do it ?
Upvotes: 0
Views: 9460
Reputation: 687
If you're stuck with outlook for some reason, try this:
using Outlook = Microsoft.Office.Interop.Outlook;
int pos = (int)email.Body.Length + 1;
int attType = (int)Outlook.OlAttachmentType.olByValue;
email.Attachments.Add("file.txt", attType, pos, "File description.");
where:
Outlook.MailItem email = (Outlook.MailItem)_outlookAppInstance.CreateItem(Outlook.OlItemType.olMailItem);
Upvotes: 2
Reputation: 2218
Better use MailMessage instead.
There's an example on how to use it with attachment here(Scroll down to "Examples"):
http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx
Not only will you get a managed framework for sending mails, but also whoever runs the code will not need Outlook installed and running.
Upvotes: 3