Nirvana
asked on
send bulk mails from drafts folder
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
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
Set xDraftFld = xAccount.DeliveryStore.Get
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
Set xDraftFld = xAccount.DeliveryStore.Get
Set xDraftsItems = xDraftFld.Items
For i = xDraftsItems.Count To 1 Step -1
If i = 1 Then
Set xNewMail = Outlook.Application.Create
With xNewMail
.SendUsingAccount = xDraftsItems.Item(i).SendU
.To = xDraftsItems.Item(i).To
.CC = xDraftsItems.Item(i).CC
.BCC = xDraftsItems.Item(i).BCC
.Subject = xDraftsItems.Item(i).Subje
If xDraftsItems.Item(i).Attac
xTmpPath = "C:\MyTempAttachments"
If Dir(xTmpPath, vbDirectory) = "" Then
MkDir xTmpPath
End If
For k = xDraftsItems.Item(i).Attac
xFilePath = xTmpPath & "\" & xDraftsItems.Item(i).Attac
xDraftsItems.Item(i).Attac
xNewMail.Attachments.Add (xFilePath)
Kill xFilePath
Next k
RmDir xTmpPath
End If
.HTMLBody = xDraftsItems.Item(i).HTMLB
.Send
End With
xDraftsItems.Item(i).Delet
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
ASKER
Thank you, but everything is going to deleted folder. is there any other solution?
No, if you REMOVE that line, it should STAY in the Drafs folder.
Just passing by, but normally when you compose an email it resides in the Drafts folder, and then when you send it it gets moved fist to the Outgoing folder, and then when transmission is complete to the Sent Items folder. Have you checked there for it?
»bp
»bp
ASKER
Hi Bill,
As soon I run the macro, it says "Successfully sent" but directly goes and sits in deleted folder. these email messages are copied to "drafts folder" from local drive. not composed and which got saved to Drafts
Stay safe. Be healthy!!
As soon I run the macro, it says "Successfully sent" but directly goes and sits in deleted folder. these email messages are copied to "drafts folder" from local drive. not composed and which got saved to Drafts
Stay safe. Be healthy!!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Open in new window