By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 2,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

MS Outlook VBA Script - Automatic Print ORIGINAL email when it gets undelivered

P: 5
I'm using MS Office 2016 Desktop App on Windows 10 and looking for some functionality which I didn't find any success after searching online a lot and also contacted MS Outlook Support to only find that there is no easy way to achieve it except VBA script. Here's what I'm looking for:

I'm sending individual mail to a huge bulk of people having individual information and individual attachment. What I want is that when the emails don't get sent successfully to few of them (because of the incorrect email provided or some other reason), I want to perform some action on the Original emails (ones which were not delivered to the receiver instead of undeliverable mail from MS Outlook) when this happens. Possible actions could be primarily printing the original mail and its attachments automatically or forwarding all such original emails to some other email automatically.

The reason I want this automation is that it is very difficult and burdensome to print individual emails from around 1000s of emails daily. Unfortunately, MS Outlook rules don't provide the condition for 'when email undelivered' or similar. I'm not sure if VBA script helps me for this case as I have no idea about VBA. I would like to know if this can be achieved with VBA script. If yes, then any help with VBA code would be very welcomed. Thank you in advance.
Jan 22 '19 #1
Share this Question
Share on Google+
3 Replies


ADezii
Expert 5K+
P: 8,597
  1. Simplistically, you would need to query the Sent Property of a MailItem Object. If it returns True, then the E-Mail was Sent, if not then it wasn't.
  2. This is easier said then done since the Object Variable Referencing the MailItem Object becomes meaningless once the E-Mail has been sent.
  3. You can try 'Hooking' the Send() Event of the MailItem Object and testing the Sent Property within it.
  4. The general idea, not tested, would be:
  5. In a Class Module:
    Expand|Select|Wrap|Line Numbers
    1. Public WithEvents oMailSent As Outlook.MailItem
    2.  
  6. Create an Instance of the Class and set a Reference to oMailSent.
  7. Write Code in the Send() Event of oMailItem to return the Value (Boolean) of the Sent Property and proceed accordingly.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub oMailSent_Send(Cancel As Boolean)
    2. On Error Resume Next
    3.  
    4. Dim blnSent As Boolean       'Just used to generate an Error Code
    5.  
    6. blnSent = oMailSent.Sent
    7.  
    8. If Err.Number <> 0 Then     'Assume E-Mail wasn't sent
    9.   'process here
    10. End If
    11. End Sub
P.S. - All of this is simply Theory and Air Code on my part.
Jan 23 '19 #2

P: 5
I really appreciate your reply and you are special. However, I'm new to VBA script and trying to figure out how to write VBA script. I can't expect everything from you. You are the best! I will get back to you if it works. Thanks mate!
Jan 23 '19 #3

ADezii
Expert 5K+
P: 8,597
I am extremely busy right now, but as soon as things slow down, I'll see what I can come up with for you.
Jan 24 '19 #4

Post your reply

Sign in to post your reply or Sign up for a free account.