Send bulk mails from drafts;
I am using the below code to send mails from drafts folder. however, they are getting deleted,
https://www.extendoffice.com/documents/outlook/5064-outlook-send-multiple-drafts-at-once.html
Sub SendAllDraftEmails()
Dim xAccount As Account
Dim xDraftFld As Folder
Dim xItemCount As Integer
Dim xDraftsItems As Outlook.Items
Dim xPromptStr As String
Dim xYesOrNo As Integer
Dim i, k As Long
Dim xNewMail As MailItem
Dim xTmpPath, xFilePath As String
On Error Resume Next
xItemCount = 0
For Each xAccount In Outlook.Application.Sessio
n.Accounts
Set xDraftFld = xAccount.DeliveryStore.Get
DefaultFol
der(olFold
erDrafts)
xItemCount = xItemCount + xDraftFld.Items.Count
Next xAccount
Set xDraftFld = Nothing
If xItemCount > 0 Then
xPromptStr = "Are you sure to send out all the drafts?"
xYesOrNo = MsgBox(xPromptStr, vbQuestion + vbYesNo, "Kutools for Outlook")
If xYesOrNo = vbYes Then
For Each xAccount In Outlook.Application.Sessio
n.Accounts
Set xDraftFld = xAccount.DeliveryStore.Get
DefaultFol
der(olFold
erDrafts)
Set xDraftsItems = xDraftFld.Items
For i = xDraftsItems.Count To 1 Step -1
If i = 1 Then
Set xNewMail = Outlook.Application.Create
Item(olMai
lItem)
With xNewMail
.SendUsingAccount = xDraftsItems.Item(i).SendU
singAccoun
t
.To = xDraftsItems.Item(i).To
.CC = xDraftsItems.Item(i).CC
.BCC = xDraftsItems.Item(i).BCC
.Subject = xDraftsItems.Item(i).Subje
ct
If xDraftsItems.Item(i).Attac
hments.Cou
nt > 0 Then
xTmpPath = "C:\MyTempAttachments"
If Dir(xTmpPath, vbDirectory) = "" Then
MkDir xTmpPath
End If
For k = xDraftsItems.Item(i).Attac
hments.Cou
nt To 1 Step -1
xFilePath = xTmpPath & "\" & xDraftsItems.Item(i).Attac
hments.Ite
m(k).FileN
ame
xDraftsItems.Item(i).Attac
hments.Ite
m(k).SaveA
sFile xFilePath
xNewMail.Attachments.Add (xFilePath)
Kill xFilePath
Next k
RmDir xTmpPath
End If
.HTMLBody = xDraftsItems.Item(i).HTMLB
ody
.Send
End With
xDraftsItems.Item(i).Delet
e
Else
xDraftsItems.Item(i).Send
End If
Next
Next xAccount
MsgBox "Successfully sent "
End If
Else
MsgBox "No Drafts!", vbInformation + vbOKOnly
End If
End Sub
Open in new window