0

我正在将 EWS 与 JScript 一起使用(我知道,不推荐,但我别无选择!)...

我可以连接到我的 Exchange 服务器、登录、检索邮件以及识别带有文件附件的邮件。现在我想在本地保存该附件。

我有:

  for (x = 0; x < myMessages.Items.Count - 1; x++)
  {
    thisitem = myMessages.Items.get_Item(x);
    if (thisitem.HasAttachments)
    {
      attachment = thisitem.Attachments.get_Item(0)
      attachment.Load("c:\\temp.xls");

但这会产生错误:

mscorlib

System.ArgumentException:“System.String”类型的对象无法转换为“System.IO.Stream”类型......

我知道附件是一个 XLS ......这与 Load 方法的重载有关......但除此之外我迷路了。

帮助?!

4

1 回答 1

0

For anyone needing to do something like this, in the end I found this worked (this is Jscript in TestComplete - amend as you need to!):

  if (thisitem.HasAttachments)
  {
    for (y = 0; y < thisitem.Attachments.Count; y++)
    {
      var attachment = thisitem.Attachments.get_Item(y);
      if (attachment.get_IsInline() == false)
      {
        if (attachment.name.OleValue.indexOf(attachsuffix) == attachment.name.OleValue.length - attachsuffix.length)
        {
          attachment.Load();
          aqFileSystem.CreateFolder(targetfolder)
          var filename = targetfolder + attachment.Name.OleValue
          var fos = dotNET.System_IO.BinaryWriter.zctor(dotNET.System_IO.File.Open(filename, dotNET.System_IO.FileMode.Create))
          fos.write_3(attachment.content)
          fos.Close();
          Log.Message("Saved: " + filename);
        }
      }
    }
  }
于 2013-10-10T10:05:11.333 回答