首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >第二次添加Outlook附件时在Outlook临时文件夹中创建的VB0B临时文件

第二次添加Outlook附件时在Outlook临时文件夹中创建的VB0B临时文件
EN

Stack Overflow用户
提问于 2020-07-20 14:46:57
回答 2查看 49关注 0票数 0

这种行为很奇怪,也很难描述,所以我会尽我最大的努力。

  1. 在Outlook关闭后,文件通常会一次又一次地附加。
  2. 在Outlook打开后,文件通常第一次附加,然后每次创建一个0B临时文件。
  3. 删除Content.Outlook没有任何效果。
  4. 不管我要附加的pdf文件是什么,都是成功创建的。当复制到要附加的临时目录时,它似乎失败了。

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

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

代码语言:javascript
运行
复制
    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
EN

Stack Overflow用户

发布于 2020-07-20 16:52:31

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

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

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62997978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档