【问题标题】:VB 0B temp file created in Outlook temp folder when adding Outlook attachment for second time第二次添加 Outlook 附件时在 Outlook 临时文件夹中创建的 VB 0B 临时文件
【发布时间】:2020-07-21 02:07:59
【问题描述】:

这种行为很奇怪,很难描述,所以我会尽力而为。

  1. 关闭 Outlook 后,文件会一次又一次地正常附加。
  2. 打开 Outlook 后,第一次正常附加文件,之后每次都创建一个 0B 临时文件。
  3. 删除 Content.Outlook 无效。
  4. 无论我尝试附加的 pdf 文件是什么,总是可以成功创建。复制到要附加的临时目录时似乎失败了。

因此,出于某种原因,打开 Outlook 会阻止我多次成功运行以下代码。

这是创建附件并将附件添加到电子邮件的代码。

    Me.PrintForm1.PrintFileName = Jobpath & "\DrawingChecklist.pdf"
    PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)

    'Log
    My.Computer.FileSystem.WriteAllText(My.Application.Info.DirectoryPath & "\" & "Log.txt", "User: " & Environment.UserName & " Saved: " & txtQuoteNumber.Text & " at: " & DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") & Environment.NewLine, True) 'True appends, False overwites

    Dim OutlookMessage As Outlook.MailItem
    Dim AppOutlook As New Outlook.Application


    Try

        'Make sure file has been created
        Dim xx = 0
        Do While Dir(Jobpath & "\DrawingChecklist.pdf") = "" And xx < 10
            'MsgBox("File doens't exist." & " " & Jobpath & "\DrawingChecklist.pdf")
            xx = xx + 1
            Threading.Thread.Sleep(100)
        Loop

        'Double check file has been created
        If Dir(Jobpath & "\DrawingChecklist.pdf") = "" Then
            MsgBox("File doens't exist." & " " & Jobpath & "\DrawingChecklist.pdf")
        End If

        OutlookMessage = AppOutlook.CreateItem(Outlook.OlItemType.olMailItem)
        Dim Recipents As Outlook.Recipients = OutlookMessage.Recipients
        Recipents.Add(File.ReadAllText(ExePath & "DraftingEmail.txt"))
        Recipents.ResolveAll()
        OutlookMessage.Subject = txtCompany.Text & " " & txtQuoteNumber.Text & " " & txtJobName.Text
        OutlookMessage.Attachments.Add(Jobpath & "\DrawingChecklist.pdf")

        OutlookMessage.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
        OutlookMessage.Display()
        'OutlookMessage.Send()
        'MsgBox("Mail sent!")



        'Catch ex As Exception
        'MessageBox.Show("Mail could Not be sent") 'if you dont want this message, simply delete this line 
    Finally
        OutlookMessage = Nothing
        AppOutlook = Nothing
    End Try

【问题讨论】:

  • Jobpath 代表什么?
  • 这只是附件存储的路径。
  • 在哪里?它看起来怎么样?
  • “\\acs03\gmapp\Quotes\TESTZACH\test\zt20-02_test”就是一个例子。
  • 本地文件有问题吗?

标签: vb.net outlook


【解决方案1】:

Attachments.Add 方法在Attachments 集合中创建一个新附件。附件的来源可以是文件(由带有文件名的完整文件系统路径表示)或构成附件的 Outlook 项目。

该文件应位于本地磁盘上 - 您需要先将其下载到本地驱动器上。

【讨论】:

  • 是否可以在不先复制到本地的情况下附加文件?
  • Office 应用程序旨在仅处理本地文件。因此,建议处理本地文件。此外,远程位置可能处于离线状态或只是存在网络延迟问题。
  • 所以我最好的选择是在本地复制文件,附加它,然后删除本地文件?
  • 文件复制为 0 KB 大小,这没有任何意义。这几乎就像文件打开了或类似的东西,但我找不到任何可以打开它的东西,除非应用程序本身在创建它后将其锁定。
【解决方案2】:

通过在添加附件之前添加一个短暂的延迟来解决问题。

Threading.Thread.Sleep(300)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 2016-03-11
    • 1970-01-01
    相关资源
    最近更新 更多