我正在尝试使用 VBA 发送带有到期时间的消息。
如果我将电子邮件发送给自己或 Office 365 内同一组织中的人员,则该代码有效。
但是,当我发送给其他 Office 365 组织中的人员时,过期时间不会过去。
有什么解决办法吗?或者有没有办法设置保留期?我在 Outlook 中看到可以为收到的单封电子邮件设置保留期,但不知道如何在 VBA 中设置。
Sub testEmail()
Dim OutlookApp As Outlook.Application
Dim myMsg As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set OutlookApp = New Outlook.Application
Set myMsg = OutlookApp.CreateItem(olMailItem)
'attach the document if NOT being uploaded OR if the "Attach Anyway" override = "Yes"
If Sheet5.Cells(2, Sheet5.Range("FileShareLocation").Column) = "" _
Or Sheet5.Cells(2, Sheet5.Range("AttachOverride").Column) = "Yes" _
Then
If Sheet5.Cells(2, Sheet5.Range("ZipFile").Column) = "Yes" Then
myAttachments.Add strSaveToPath & strFileNameZip
Else
myAttachments.Add strSaveToPath & strFileName
End If
End If
strSubject = "Test - expires " & Now + 30
strBody = "Hello," & "<br><br>" & "Test - expires " & Now + 30
With myMsg
.BodyFormat = olFormatHTML
.Display
.HTMLBody = strBody & _
.HTMLBody 'last .HTMLBody includes signature from the outlook.''<br> includes line breaks b/w two lines
.To = "[email protected]"
.Subject = strSubject
.ExpiryTime = Now + 30 'set it to expire in 30 days so the inbox doesn't stay junked up (especially if we're sending attachments)
.CC = ""
.BCC = ""
'.Attachments = ThisWorkbook
'.Send
End With
End Sub
MailItem.ExpiryTime 属性返回或设置一个日期,指示该项目变得无效并可以删除的日期和时间。 Outlook 客户端不包含自动删除过期邮件的方法,但它确实使用删除线字体修饰符显示它们。
如果 MailItem.RetentionExpirationDate 属性在 Outlook 对象模型中可用,则为指定
MailItem
对象过期日期的日期,在此之后,邮件记录管理 (MRM) 助手将删除该项目,而不是 Outlook。保留策略由 Exchange Server 管理员在邮箱级别启用和禁用。此功能仅在启用了 MRM 2.0 或更高版本的 Exchange 邮箱上可用。
如果 Outlook 处于缓存或脱机模式,Microsoft Outlook 会根据项目保留开始日期和保留期计算此属性的值。如果 Outlook 处于在线模式,则 Exchange Server 指定该值。
一般来说,项目的保留开始日期确定如下: