Public Sub SendWithoutSave()
'perform the send Dim oInsp As Outlook.Inspector Dim oMail As Outlook.MailItem Dim oCntr As Object Dim bNoMailItem As Boolean 'make sure the function is invoked from a mail item If TypeName(Application.ActiveWindow) = "Inspector" Then 'There is an inspector! Set oInsp = Application.ActiveInspector 'Is it really a mail item? If TypeName(oInsp.CurrentItem) <> "MailItem" Then bNoMailItem = True End If Else bNoMailItem = True End If If bNoMailItem Then MsgBox "This Function must be invoked from within a mail item" Exit Sub End If Set oMail = oInsp.CurrentItem 'prevent from save oMail.DeleteAfterSubmit = True 'Send it oMail.Send End Sub Public Sub AddButton() 'Add the command bar button "Send/Delete" to the inspector's toolbar Dim oInsp As Inspector Dim bDontClose As Boolean Dim cbb As CommandBarButton Dim cbbSend2 As CommandBarButton Dim cbStandard As CommandBar 'open the appropriate inspector Set oInsp = Application.CreateItem(olMailItem).GetInspector On Error Resume Next 'check whether button exists Set cbStandard = oInsp.CommandBars("Standard") Set cbb = cbStandard.FindControl(, , "SendWithoutSave") If Not cbb Is Nothing Then 'already exists -> nothing to do Exit Sub End If 'doesn't exist -> put it after the "Send" item (ID=2617) Set cbb = cbStandard.FindControl(ID:=2617) Set cbbSend2 = cbStandard.Controls.Add(msoControlButton, before:=cbb.Index + 1) cbbSend2.TooltipText = "Send this mail without saving it into the Sent Items folder" cbbSend2.Caption = "Send/Delete" cbbSend2.Tag = "SendWithoutSave" 'assign the proc to be called cbbSend2.OnAction = "SendWithoutSave" 'needed to commit our actions ... oInsp.Close olDiscard End Sub |