【问题标题】:How do you add drag-n-drop upload ability from Outlook to a Web form?如何将 Outlook 中的拖放上传功能添加到 Web 表单?
【发布时间】:2023-04-06 10:49:02
【问题描述】:

我正在寻找一种允许用户以简单的方式将 Outlook 电子邮件上传到基于 Web 的系统的方法。

我可以让它以手动方式为用户工作。他们可以将电子邮件从 Outlook 拖放到他们的桌面,从而创建一个 .msg 文件。这很好用,尤其是。如果电子邮件中的附件也存储在 .msg 文件中。然后可以使用传统的“输入类型=文件”html 字段上传此文件。

如果可能的话,我想简化这个过程。我看到一些网站对存在于硬盘上的文件具有拖放上传功能。

但是,我不确定是否存在任何允许从 Outlook 直接拖放的东西,它可以创建 .msg 文件或类似文件并处理文件上传。换句话说,一种解决方案,可以省去将电子邮件消息拖到桌面以创建临时 .msg 文件进行上传的手动步骤。

这可能吗?如果可以,怎么做?所有用户目前都使用 Windows XP 并拥有 Outlook 2007、IE6 或更高版本以及 Firefox。后端服务器正在为相关应用程序运行 Java(我们的编程人员使用带有 C# 的 ASP.NET 进行 Web 开发),但我认为任何解决方案都将主要基于 Flash 或 JQuery 等客户端技术。

【问题讨论】:

    标签: html upload outlook drag-and-drop


    【解决方案1】:

    我认为你不会使用 jQuery / JavaScript 来实现这一点 - 你可能有机会使用 Flash 之类的东西。

    作为替代方案,您能否创建一个简单的客户端应用程序,让他们可以在桌面上运行,让他们可以将消息拖到上面 - 这样,您就可以完全信任地运行并执行您希望获得的任何任务文件并从这个应用程序上传(这是我曾经工作过的文件扫描应用程序使用的解决方案 - 我们有一个小窗口,用户可以将文件或电子邮件拖到上面以启动上传到扫描存储。

    【讨论】:

      【解决方案2】:

      您最终是如何实现这一点的?我一直在寻找类似的解决方案,但找不到太多,所以最终在 Outlook 中使用了 VBA 宏,他们在选择消息时单击该宏。然后将消息作为 .msg 复制到他们的临时文件夹,然后提交到 HTML 表单。

      我已经添加了我从各种网络资源(包括这里 - 抱歉,我不记得保存链接)拼凑在一起的代码,以防有人想做同样的事情。

      我确信它可以被优化等,因为我对 VBA 很陌生(昨天!)但它现在可以完成工作,虽然我想我想做的是检查是否存在 IE 窗口并添加一个新选项卡而不是而不是每次点击都打开一个新的浏览器。

      ' Function to maximize IE window
      Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
      
      Global Const SW_MAXIMIZE = 3
      Global Const SW_SHOWNORMAL = 1
      Global Const SW_SHOWMINIMIZED = 2
      
      Sub test()
       'the mail we want to process
      Dim objItem As Outlook.MailItem
       'question for saving, use subject to save
      Dim strPrompt As String, strname As String
       'variables for the replacement of illegal characters
      Dim sreplace As String, mychar As Variant, strdate As String
       'put active mail in this object holder
      Set objItem = Outlook.ActiveExplorer.Selection.Item(1)
       'check if it's an email ... need to take a closer look cause
       'gives an error when something else (contact, task) is selected
       'because objItem is defined as a mailitem and code errors out
       'saving does work, if you take care that a mailitem is selected
       'before executing this code
      If objItem.Class = olMail Then
           'check on subject
          If objItem.Subject <> vbNullString Then
              strname = objItem.Subject
          Else
              strname = "No_Subject"
          End If
          strdate = objItem.ReceivedTime
           'define the character that will replace illegal characters
          sreplace = "_"
           'create an array to loop through illegal characters (saves lines)
          For Each mychar In Array(" ", "/", "\", ":", "?", Chr(34), "<", ">", "¦")
               'do the replacement for each character that's illegal
              strname = Replace(strname, mychar, sreplace)
              strdate = Replace(strdate, mychar, sreplace)
          Next mychar
           'Prompt the user for confirmation
          strPrompt = "Upload the email to CRM?"
          If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
              Dim location As String
              Dim tempPath As String
              tempPath = IIf(Environ$("tmp") <> "", Environ$("tmp"), Environ$("temp"))
              location = tempPath & "\" & strname & "-" & strdate & ".msg"
              objItem.SaveAs location, olMSG
              'upload to IE
              UploadFile "http://intranet/test.php", location, "msgupload"
          End If
      End If
      End Sub
      
      '******************* upload - begin
      'Upload file using input type=file
      Sub UploadFile(DestURL As String, FileName As String, _
        Optional ByVal FieldName As String = "File")
        Dim sFormData As String, d As String
        'Boundary of fields.
        'Be sure this string is Not In the source file
        Const Boundary As String = "---------------------------0123456789012"
        'Get source file As a string.
        sFormData = GetFile(FileName)
        'Build source form with file contents
        d = "--" + Boundary + vbCrLf
        d = d + "Content-Disposition: form-data; name=""" + FieldName + """;"
        d = d + " filename=""" + FileName + """" + vbCrLf
        d = d + "Content-Type: application/upload" + vbCrLf + vbCrLf
        d = d + sFormData
        d = d + vbCrLf + "--" + Boundary + "--" + vbCrLf
        'Post the data To the destination URL
        IEPostStringRequest DestURL, d, Boundary
      End Sub
      
      'sends URL encoded form data To the URL using IE
      Sub IEPostStringRequest(URL As String, FormData As String, Boundary As String)
        'Create InternetExplorer
        Dim WebBrowser: Set WebBrowser = CreateObject("InternetExplorer.Application")
        'You can uncoment Next line To see form results
        WebBrowser.Visible = True
        'Send the form data To URL As POST request
        Dim bFormData() As Byte
        ReDim bFormData(Len(FormData) - 1)
        bFormData = StrConv(FormData, vbFromUnicode)
        ' Submit message to intranet
        WebBrowser.Navigate2 URL, , , bFormData, "Content-Type: multipart/form-data; boundary=" + Boundary + vbCrLf
        ' Maximize window
        apiShowWindow WebBrowser.hwnd, SW_MAXIMIZE
      End Sub
      
      'read binary file As a string value
      Function GetFile(FileName As String) As String
        Dim FileContents() As Byte, FileNumber As Integer
        ReDim FileContents(FileLen(FileName) - 1)
        FileNumber = FreeFile
        Open FileName For Binary As FileNumber
          Get FileNumber, , FileContents
        Close FileNumber
        GetFile = StrConv(FileContents, vbUnicode)
      End Function
      '******************* upload - end
      

      捕获文件的简单 PHP 脚本如下:

      <?php
      if($_FILES['msgupload']){
      move_uploaded_file($_FILES['msgupload']['tmp_name'], "./crm_uploads/".substr($_FILES['msgupload']['name'], 0 ,-24).".msg");
      print("You are adding the email '".substr($_FILES['msgupload']['name'], 0, -24)."'");
      print("<br />dated ".substr($_FILES['msgupload']['name'], -23, -4));
      }
      ?>
      

      【讨论】:

        【解决方案3】:

        你可以试试

        http://xupload.aspupload.com/

        它是一个 ActiveX 控件,因此仅适用于 IE,但从 Outlook 拖放不是问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-02-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-06-26
          相关资源
          最近更新 更多