【发布时间】:2022-01-27 22:47:50
【问题描述】:
我有一些代码可以检查邮件项何时被放入特定文件夹并循环通过“x”个邮件项并将它们自动转发到另一个电子邮件地址。我遇到的问题是,当我一次丢弃超过 2 封电子邮件时,它只会拾取前两封电子邮件,然后就无法识别任何内容。有谁知道 Outlook 是否对在特定时间范围内发送电子邮件有限制?我正在考虑在每封电子邮件之间添加某种延迟或计时器,看看是否可以解决问题。
如果文件夹中存在现有邮件项,该代码似乎也不起作用,它仅在代码运行时才起作用,然后用户将邮件项放入文件夹中。
任何建议将不胜感激。
Public WithEvents objInbox As Outlook.Folder
Public WithEvents objInboxItems As Outlook.Items
Private Sub Application_StartUp()
Dim olNs As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Set olNs = Application.GetNamespace("MAPI")
Set objInbox = olNs.Folders("test2@test.com").Folders("test")
Set objInboxItems = objInbox.Items
End Sub
Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
Dim objMail As Outlook.MailItem
Dim objForward As Outlook.MailItem
Dim olNs As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Dim olAtt As Attachment
Dim olAtts As Attachments
Dim olSentAtts As Attachments
Set olNs = Application.GetNamespace("MAPI")
'Set shrdRecip = olNs.CreateRecipient("test1@test.com")'
Set objInbox = olNs.Folders("test2@test.com").Folders("test")
Set objForward = Item.Forward
Set destFolder = olNs.Folders("test1@test.com").Folders("arch")
Set srcFolder = olNs.Folders("test2@test.com")
'MsgBox (objMail)'
'objMail.UnRead Or objMail.Sent'
For Each Item In objInbox.Items
If TypeName(Item) = "MailItem" Then
Set objForward = Item.Forward
With objForward
.Subject = Item.Subject
.HTMLBody = "<HTML><BODY>This message contains an invoice from test1</BODY></HTML>" & objForward.HTMLBody
.Recipients.Add ("test2@test.com")
.Recipients.ResolveAll
'printradu ()'
.Display
MsgBox (Item.Subject)
MsgBox (TypeName(Item))
Dim FilePath As String
FilePath = "C:\Logs\OutlookLogs.txt"
TextFile = FreeFile
'End If'
End With
If Err Then
'MsgBox (Item.Subject + "Failed to send due to: " + Err + "." + "Please try again.")'
Open FilePath For Append As #1
Write #1, (CStr(Item.Subject) + " Failed to send due to error code: " + CStr(Err.Description) + "." + "Please try again.")
'Print #TextFile, (Item.Subject + "Failed to send due to: " + Err + "." + "Please try again.")'
Close #1
Item.Move (srcFolder)
Else
'MsgBox (Item.Subject + " has been sent successfully.")'
Open FilePath For Append As #1
Write #1, ("Subject: " + Item.Subject + " Sent time: " + CStr(Item.SentOn) + " Receieved at: " + CStr(Item.ReceivedTime) + " has been sent successfully.")
'Print #TextFile, (Item.Subject + " has been sent successfully.")'
Close #1
Item.Move (destFolder)
'Item.Move (destFolder)'
End If
End If
Next Item
'End If'
'Next'
'End Sub'
End Sub
Sub MyTEST()
End Sub
【问题讨论】: