Вопрос

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 + "\"");
 }
Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top