1

I just want to open the outlook "New Email" window and populate with multiple attachments, I figure Process.Start would be easier than SMTP because I don't have to pass in my SMTP server. My original plan was to use Microsoft.Office.Interop.Outlook, but since I am running my application as administrator, I had to rule this option out.

This is what I have so far, it only takes one attachment, is it possible I can pass in a second argument (fn2) after fn?

static void Main(string[] args)
{
     string programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
     var selectedApplicationPath = Directory.GetFiles(programFilesPath, "Outlook.exe", SearchOption.AllDirectories);
     if (selectedApplicationPath.Length <= 0) return;

     var outlookProcessPath = selectedApplicationPath[0];
     if (string.IsNullOrWhiteSpace(outlookProcessPath)) return;
     string fn = @"path1";
     string fn2 = @"path2";
     Process.Start(outlookProcessPath, "/a \"" + fn + "\"");
 }
Community
  • 1
  • 1
HoKy22
  • 4,057
  • 8
  • 33
  • 54
  • *Why* can't you use Outlook Interop? – Rowland Shaw Feb 07 '14 at 20:14
  • It's difficult to explain; it's like when you started your application as admin, outlook would assume that is an user already. Therefore, outlook will not allow you to have a second user. – HoKy22 Feb 07 '14 at 20:22

1 Answers1

1

The answer is, unfortunately: You can't. The Outlook command line switches do not support attaching multiple files.

If you really want to use this approach to starting outlook, zip your attachments into a single file, then attach that.

If you need user interactivity when sending the email, I'd suggest revisiting the COM approach. I know you've discarded that, but I'm not convinced your technical issue cannot be solved (hint: start a stack overflow question).

If you do not need user interactivity, by all means use SMTP. Firing up a new outlook instance for each message tends to be rather fragile, as one hanging instance can stop all subsequent instances from appearing.

Paul-Jan
  • 16,746
  • 1
  • 63
  • 95
  • Zip it and email is a really good idea! I was able to implement instead following this approach - http://stackoverflow.com/questions/6386113/using-system-io-packaging-to-generate-a-zip-file – HoKy22 Feb 10 '14 at 20:07