473,413 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

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

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
3 1551
ADezii
8,834 Expert 8TB
  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
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
8,834 Expert 8TB
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

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

Similar topics

0
by: jags_32 | last post by:
We are trying to automate notification by email when a SQL Server goes down, no matter how the Alert is configured, it does not seem to work. We do see the message in the event log but the alert is...
2
by: peter.mcclymont | last post by:
Hi There, I am using a PrintPreviewDialog and I would like it to close the print preview dialog when I press the escape key. What is the best way to do that? I tried to make myself a new...
34
by: majahops via WebmasterKB.com | last post by:
When I click "save" after adding a new record (which contains, among other fields, the person's email address), I want an email to automatically be sent to that person (at the email that is in the...
5
by: musai | last post by:
Hi Members What I want to know is, How to avoid outlook seurity msgbox while sending email through VBA I have used Outlook to send mail. How to avoid..... Pleae.....
5
by: canajien | last post by:
I have a form that stores information in a table, but I also need it to send an email when a specific question, among the many, is answered with no the question is a simple drop box: <select...
0
by: canajien | last post by:
I have a form that when submitted uses php to store the information in a table, but I also need it to send an email when a condition is met <select name="safe_access"> <option...
1
by: pelusa | last post by:
hello all, i need help modifying a small perl script that sends an email after a form is submitted. i need to be able to receive the email in html format, but my knwoledge of perl is very poor....
1
by: Garima12 | last post by:
How do websites send email when new answers is posted to question like if you answer this question, I will get automated email that my question has an answer?
1
by: Adam Docrat | last post by:
Hi there, I have created an MS Access database for use as a "helpdesk" system for the company that I work for. Records are detailed as "requests" and the status of the requests are changed as...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.