Tuesday, November 12, 2019

email - Outlook VBA to create autoreply with number of unread mails in inbox

I am trying to create an autoreply where I could trigger a script with rules to send an autoreply.


"Hi thanks for your mail, your mail has been placed in a queue there are XX number of e-mails in front of you, we will answer as soon as possible."
The XX should be the number of unread e-mails.


I found this:


Private Sub myOlItems_ItemAdd(ByVal Item As Object)
End Sub
Sub AutoResponse(objmsg As Outlook.MailItem)
' define my reply message
Dim objReply As MailItem
' let's get ourselves the inbox!
Dim inbox As MAPIFolder
Set inbox = Application.GetNamespace("MAPI"). _
GetDefaultFolder(olFolderInbox)
' Let's get this reply going!
Set objReply = objmsg.Reply
' Subject Re: their subject. Standard
objReply.Subject = "Re: " & objReply.Subject
' Body - you define this, use the variable for the unread count in inbox
objReply.Body = "Your email has been received. I currently have " & inbox.UnReadItemCount & " unread emails in my inbox and I will get yours as soon as I can"
' Send this thing!
objReply.Send
' Reset
Set objReply = Nothing
End Sub

Here


But it doesn't seem to be working.
I am on Outlook 2016, with an exchange mail server.


Thanks

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...