0

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 ?

4
  • 3
    Yes, it is. Have you tried? What have you tried? Did it work? Commented Apr 8, 2012 at 15:09
  • 1
    Any reason you specifically use Outlook interop over MailMessage?
    – Svarog
    Commented Apr 8, 2012 at 15:22
  • no, i only looking for a automatic way to send email using outlook, u know better way ?
    – Dana Yeger
    Commented Apr 8, 2012 at 15:25
  • Cool question. here's what i found stackoverflow.com/questions/4312687/… Commented Apr 8, 2012 at 16:23

2 Answers 2

3

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.

2
  • string server mean my SMTP server ?
    – Dana Yeger
    Commented Apr 8, 2012 at 15:46
  • after send the email i see with wireshark smtp packets but the email did not arrive
    – Dana Yeger
    Commented Apr 8, 2012 at 15:58
2

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);
1
  • 1
    Horrid thing to have to do. +1 for effort!
    – Robino
    Commented May 7, 2014 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.