VBA to remove deferred delivery on a MeetingItem

Status
Not open for further replies.

Michael Nagy

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
To prevent compliance breeches I'm writing some code to delay sending of emails to external recipients.
A familiar problem but solutions I've seen only address email but no other Outlook types.

Most of my code works OK but I am having trouble removing the delay on a delayed MeetingItem.

Urgent items can be sent immediately by re-sending them again from the Outbox. The code should remove any existing delay, therefore sending immediately.

The following works for MailItems but fails for MeetingItem as meeting updates don't seem to inherit the existing delay.

Dim objNamespace As Outlook.NameSpace
Dim objItem As Object ' can be MailItem, MeetingItem etc
Dim objRecips As Outlook.Recipients
Dim objAttachments As Outlook.Attachments

Dim iCounter As Integer
Dim strMsgExtRecips As String
Dim strMsgAttachments As String
Dim strPrompt As String

Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Const NoDeferredDelivery As String = "1/01/4501" ' Magic number Outlook uses for "delay mail box isn't checked"

Set objNamespace = Application.GetNamespace("MAPI")
Set objItem = Item 'Set object to the email just sent

' If item is currently delayed, remove the delay and quit.
If objItem.DeferredDeliveryTime <> NoDeferredDelivery Then
strPrompt = "Do you want to send immediately?"
If (MsgBox(strPrompt, vbYesNo + vbInformation + vbMsgBoxSetForeground, "Delivery delay will be removed") = vbYes) Then
objItem.DeferredDeliveryTime = NoDeferredDelivery
GoTo Procedure_Exit
Else
Cancel = True
GoTo Procedure_Exit
End If
End If

Any pointers greatly appreciated.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
How are you adding the delay? It works using a rule or using a send macro -
Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'Defer delivery time
   SendAt = DateSerial(Year(Now), Month(Now), Day(Now) + 1) + #7:00:00 AM#
Item.DeferredDeliveryTime = SendAt
End Sub
 

Michael Nagy

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Thanks for the replying Diane. First post even though Slipstick has been my go to website for Outlook VBA for years.

That's exactly the way I'm adding the delay. But I'm having trouble removing the delay for Meeting Items.
Currently I imagine users will go to the outbox and be able to immediately send any delayed items they find there if it's urgent.
I suspect I don't understand the behaviour of meeting items well enough.

I call this from Application_ItemSend:

Public Sub OutgoingExternalEmails(ByVal Item As Object, Cancel As Boolean)

' Assists in preventing compliance breaches when emails are sent to incorrect recipients
' - Presents a warning message before sending an email to an external address
' - Delays sending of external emails by a set time

Dim objNamespace As Outlook.NameSpace
Dim objItem As Object ' can be MailItem, MeetingItem etc
Dim objRecips As Outlook.Recipients
Dim objAttachments As Outlook.Attachments

Dim iCounter As Integer
Dim strMsgExtRecips As String
Dim strMsgAttachments As String
Dim strPrompt As String

Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Const NoDeferredDelivery As String = "1/01/4501" ' Magic number Outlook uses for "delay mail box isn't checked"
Const strSecurityGroup As String = "MEL_Outlook2010_PopUpMsg_Enable" ' members of this group are internal recipients. (not used at the moment)
Const iDeferredDeliveryTime As Integer = 5 ' delivery delay in minutes
Const boolDebugMode As Boolean = False ' Set to False when in production. Set to True only when testing and debugging the macro.

On Error GoTo Procedure_Error

Set objNamespace = Application.GetNamespace("MAPI")

Set objItem = Item 'Set object to the email just sent

Select Case TypeName(objItem)

Case "MailItem", "MeetingItem"

' If item is currently delayed, remove the delay and quit.
' This allows a user to go to their Outbox and send items immediately. This method is to be used for urgent items.
If objItem.DeferredDeliveryTime <> NoDeferredDelivery Then
strPrompt = "Do you want to send immediately?"
If (MsgBox(strPrompt, vbYesNo + vbInformation + vbMsgBoxSetForeground, "Delivery delay will be removed") = vbYes) Then
objItem.DeferredDeliveryTime = NoDeferredDelivery
GoTo Procedure_Exit
Else
Cancel = True
GoTo Procedure_Exit
End If
End If

' Get external recipients.
Set objRecips = objItem.Recipients
For iCounter = 1 To objRecips.Count
If objRecips.Item(iCounter).AddressEntry.Type = "SMTP" Then
strMsgExtRecips = strMsgExtRecips & vbNewLine & objRecips.Item(iCounter).Name
End If
Next iCounter

Case Else
MsgBox "Unknown Outlook Item Type"
GoTo Procedure_Exit
End Select

' If no external recipients then exit
If strMsgExtRecips = vbNullString Then GoTo Procedure_Exit

' Get list of attachments
Set objAttachments = objItem.Attachments
If objItem.Attachments.Count > 0 Then
For iCounter = 1 To objAttachments.Count
strMsgAttachments = strMsgAttachments & vbNewLine & objAttachments(iCounter).FileName
Next iCounter
End If

' Present warning message
strPrompt = vbNewLine & "Are the following recipient(s) correct?" & vbNewLine & strMsgExtRecips
strPrompt = strPrompt & vbNewLine

If Not strMsgAttachments = vbNullString Then
strPrompt = strPrompt & vbNewLine & "Are the following attachment(s) correct?" & vbNewLine & strMsgAttachments
Else
End If

If Not (MsgBox(strPrompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "External Email") = vbYes) Then
'user has cancelled message: cancel send and exit
Cancel = True
GoTo Procedure_Exit
End If

' Send with delay
If Not objItem Is Nothing Then
objItem.DeferredDeliveryTime = DateAdd("n", iDeferredDeliveryTime, Now())
End If

Procedure_Exit:
On Error Resume Next
' Clean up.
Set objNamespace = Nothing
Set objItem = Nothing
Set objRecips = Nothing
Set objAttachments = Nothing
Exit Sub

Procedure_Error:
Err.Clear
Cancel = boolDebugMode ' don't send if an error occurs while we are testing the macro but send if in production

Resume Procedure_Exit
End Sub
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
D Remove text in subject using VBA Outlook VBA and Custom Forms 4
G VBA/Macro to remove page colour when replying or forwarding email Outlook VBA and Custom Forms 2
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D.Moore VBA script fail after Office 365 update Using Outlook 8
R Limiting length of saved attachment in VBA Outlook VBA and Custom Forms 2
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
C How to use VBA to show only items x days old or more Outlook VBA and Custom Forms 1
B VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
S Reference Custom Fields with VBA Outlook VBA and Custom Forms 2
PGSystemTester VBA To Change AppointmentItem.BusyStatus From MeetingItem Before Send Using Outlook 0
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
G VBA Macro Calendar Printing Assistant 3
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
B VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
shrydvd vba to secure zip attachments Outlook VBA and Custom Forms 3
M Adding Subject to this Link-Saving VBA Outlook VBA and Custom Forms 5
N VBA to delete duplicates by message-id on common pst for 2 or more emails Outlook VBA and Custom Forms 0
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
M VBA to auto forward message with new subject and body text Outlook VBA and Custom Forms 8
A Custom VBA to sort emails into folders Outlook VBA and Custom Forms 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
R VBA for copying sent email to current folder under a shared mailbox Outlook VBA and Custom Forms 17
A Edit subject - and change conversationTopic - using VBA and redemption Outlook VBA and Custom Forms 2
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
B Clear Offline Items (Mail Folder) via VBA Outlook VBA and Custom Forms 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
D.Moore Folder view settings by VBA macro Outlook VBA and Custom Forms 57
F VBA to ensure a code is entered in Subject title Outlook VBA and Custom Forms 1
B Vba to monitor time to respond to emails using a shared mailbox Outlook VBA and Custom Forms 5
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
G Outlook VBA and Google Calendar ("Events") Outlook VBA and Custom Forms 1
B Looking to get the Recipient email address (or even the "friendly name") from an email I am replying to using VBA Outlook VBA and Custom Forms 4
J VBA Outlook : Subject line : Cut and Paste name to heading , number to very end of the body of Email Outlook VBA and Custom Forms 1
M VBA to send reminder email if no response Using Outlook 13
D Using a VBA Custom Form to Send Reoccurring Email Upon Task Completion Outlook VBA and Custom Forms 4
U Outbox Message Stuck after reading some MailItem Properties with VBA Outlook VBA and Custom Forms 1
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
M Help sending email but removing signature via VBA Outlook VBA and Custom Forms 5
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
R VBA Code to permanently delete selected email Outlook VBA and Custom Forms 10
R VBA | Chosing path to save file Outlook VBA and Custom Forms 1
Similar threads


















































Top