【发布时间】:2020-07-21 02:07:59
【问题描述】:
这种行为很奇怪,很难描述,所以我会尽力而为。
- 关闭 Outlook 后,文件会一次又一次地正常附加。
- 打开 Outlook 后,第一次正常附加文件,之后每次都创建一个 0B 临时文件。
- 删除 Content.Outlook 无效。
- 无论我尝试附加的 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”就是一个例子。
-
本地文件有问题吗?