【问题标题】:Populate an email with MULTIPLE attachments using Process.Start使用 Process.Start 填充包含多个附件的电子邮件
【发布时间】:2014-03-05 09:41:21
【问题描述】:

我只想打开 Outlook 的“新电子邮件”窗口并填充多个附件,我认为 Process.Start 会比 SMTP 更容易,因为我不必传入我的 SMTP 服务器。我最初的计划是使用Microsoft.Office.Interop.Outlook,但由于我以管理员身份运行我的应用程序,我不得不排除这个选项。

这是我目前所拥有的,它只需要一个附件,我可以在 fn 之后传入第二个参数(fn2)吗?

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 + "\"");
 }

【问题讨论】:

  • 为什么你不能使用 Outlook Interop?
  • 很难解释;就像当您以管理员身份启动应用程序时,Outlook 会假定该用户已经是用户。因此,outlook 不允许您拥有第二个用户。

标签: c# email outlook email-attachments process.start


【解决方案1】:

很遗憾,答案是:你不能。 Outlook 命令行开关不支持附加多个文件。

如果您真的想使用这种方法来启动 Outlook,请将您的附件压缩到一个文件中,然后附加该文件。

如果您在发送电子邮件时需要用户交互,我建议您重新审视 COM 方法。我知道你已经放弃了,但我不相信你的技术问题无法解决(提示:开始一个堆栈溢出问题)。

如果您不需要需要用户交互,请务必使用 SMTP。为每条消息启动一个新的 Outlook 实例往往相当脆弱,因为一个挂起的实例可以阻止所有后续实例的出现。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-19
  • 1970-01-01
  • 1970-01-01
  • 2011-01-16
  • 2015-10-13
  • 2022-01-25
相关资源
最近更新 更多