auto copy text from outlook emails and paste into another program - vba

I dont know much about programming/developing. But I am facing a dilemma at my job. About each day I have to spend 20-30 minutes doing a manual repetitive task.
open email, copy text from email, outlook.
paste copied text into another app
Instead of doing this manually: opening each email, copy text and paste the text to the matching record into the other app I was hoping this could be all done automatically.
The email matches with the other app record based off two unique control numbers.
Looking at this site, I see this question asked
Automatically export specific emails to text file from Outlook
But I am hoping anyone could maybe provide what might be the best plans to do this: not the actual steps but what language(s) could I learn that would automate the process for me.

Outlook does not like macros/programs, other than its own macros, looking at its emails. It is possible to get around this dislike but doing so will not be easy. Since you are not experienced, I believe the only suitable programming language is Outlook VBA; that is, you must write a macro to export text within Outlook.
An Outlook email can carry a text body and or an html body and or a rtf body. I have never seen a rtf body but the capability is there within Outlook. If an email has both an html and a text body, the user will see the html body. In my experience, the text body will be little more than the html body with all the formatting removed. If the html body is fairly simple, this can still give a useful text body for a macro to play with. But if the html body uses tables, for example, the text body can be useless.
How will you identify the emails from which text is to be extracted? (1) You can select one or more emails and then call a macro to process the selected emails. (2) You can run a macro at intervals to run down the Inbox looking for particular emails and process those. (3) There are more advanced techniques but get either approach 1 or 2 working then research “Outlook events”. If technique 1 appeals, look at the answer below then research "Outlook explorer". If technique 2 appeals, look at the answer recommended below.
Questions about extracting parts of emails are not uncommon. The problem with answering them is the difficulty of getting the questioner to understand that seeing an image of an email tells us little about the html that created that image. The macro in the answer below was written partly for my own research and partly to help others see the text and html bodies of their emails so they can better understand the processing required to meet their objective.
The macro in the answer, creates an Excel workbook and writes to it selected properties of selected emails. As written, the macro outputs details of every email in Inbox but contains comments explaining how to restrict output to the emails of interest. Start with this macro which contains a lot of material that you will find useful even if you decide the Outlook Explorer technique better meets your needs.
https://stackoverflow.com/a/12146315/973283

Related

Macro to mark email as read and move to folder

I'm a complete beginner with macros in Outlook, but I would like to create a macro which marks an email as read, and moves it to a specific folder. Any help most welcome. I have searched to see if this precise request has been answered elsewhere, but haven't been successful.
Many thanks,
Bevis
Note, in Outlook you can create a rule or quick action to get the job done.
If you decide to go with VBA macros you need to set up the UnRead property and call the Move method to move the item to the required folder. You may find the Getting started with VBA in Office article helpful.

Outlook VBA - How to get email item from user input

Although Im quite experienced with Excel VBA, Im not so much in regards of Outlook VBA (started yesterday, literally), so Im uncertain on how to get this simple task accomplished:
I created some coding to get a specific e-mail from the Inbox and then parse it and forward - that part is all good and well. Currently the code autodetects and retrieve the e-mail item using a set of parameters to filter through the Inbox. However, now I need to expand this code so that it can work with any e-mail item, and not only with that specific e-mail.
My idea is to get the user to input which e-mail item he/she wants to parse and forward, instead of getting the code to look in a specific place. How can that be done? The user input methods that I use regularly are InputBox (which returns a string) and GetOpenFileName, none of them suitable to pointing to a mail item within Outlook.
I thought about making the code work with the currently open e-mail item, but often the users have several e-mail items opened at once - forcing them to leave only one open for the code to work is not viable. Also, the code will be ran by people who have little to no IT expertise, so requesting things such as paths is also not an option. Is there any method for this?
I figured that working with Active MailItem is the way to go, as #niton suggested as well. I used a coding very similar to the one in this post, although I had to develop the handlers in case the user has other types of Objects active at the moment (AppointmentItems, for instance) or have multiple items selected. Final solution wasn't that much elegant - I was wishing for some sort of system input box where the user could point to the mail or something, but this works.

Embed form in outlook email and capture response

I am trying to help people do their job. So every morning an email needs to go out to the users with a list to Approve/Reject... Don't want to send this email just like a warning, telling them to go to the app to perform their duty. The email needs to have the capability to capture their response and update the DB accordingly.
option 1: Embed all items in single email body as a form, something like...
Code - Description - radiobutton - radio button
111 ABC o Accept o Reject
222 DEF o Accept o Reject
Submit
On submit need to call a winforms app and need to pass the code and accept/reject status. I have not been able to find any thing to come up with a solution. Need to validate as well, making sure all appropriate radio buttons have been selected. Is it even possible?
Option 2: I am trying to avoid voting route where each item will go as a separate email. when the user will accept/reject, a reply will go to the email. Then some process will monitor that inbox and will pick the not read messages and update DB accordingly. Using the MailItemClass in Microsoft.Office.Interop.Outlook namespace.
var mailItem = (Outlook.MailItem)Application.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.To = "some.address#server.com";
mailItem.Subject = "This is a test";
mailItem.Body = "This is the body of the message.";
mailItem.VotingOptions = "Accept; Reject;";
mailItem.Send();
I believe what you are asking for is possible but would be a lot of effort to implement.
For your approach, I assume the information for these emails comes from the DB. I would write a macro to interrogate the DB and create and send each email to the appropriate user.
On each user’s system I would have a rule that recognised these emails and called a macro to process them. The macro would extract the contents of the email, copy it to a form and pass control to the user. A Submit button would validate the user’s choices and save the results in global variables before returning control to the macro. On regaining control, the macro would update the DB.
This macro will be large and I am sure it will need maintenance. To protect itself from malware, Outlook does not provide any easy way of importing macros. The macro and the form will have to be manually imported to each user’s system, each time they change. Unless you have technically able users, it will be you who visits each system and updates it.
I would reject any approach that required code on the user’s systems.
To test an alternative approach, I manually created this email:
and sent it to myself. When I received the email, I actioned it as instructed. When I received the reply, it looked like:
The Html body for this reply is full of formatting information. You could extract the responses from it but I believe the text body would be easier. To create the following, I started with the text body, replaced every carriage return and line feed with [CR] and [LF] and then added a few new lines to make it marginally easier to read.
[CR][LF][CR][LF] [CR][LF][CR][LF]From: Tony Dallimore [mailto:a.j.dallimore#MyIsp.com] [CR][LF]Sent: 25 May 2018 14:22[CR][LF]To: 'Tony Dallimore' <a.j.dallimore#MyIsp.com>[CR][LF]Subject: Test email 2[CR][LF][CR][LF] [CR][LF][CR][LF]
Please:[CR][LF][CR][LF] [CR][LF][CR][LF]
1) Click Reply within the Home tab.[CR][LF][CR][LF]
2) You may find it helpful to click Pop Out.[CR][LF][CR][LF]
3) Enter “A” in the Accept column or “R” in the Reject column of every row in the following table.[CR][LF][CR][LF]
4) Click Send.[CR][LF][CR][LF] [CR][LF][CR][LF]Code[CR][LF][CR][LF]Description[CR][LF][CR][LF]Accept[CR][LF][CR][LF]Reject[CR][LF][CR][LF]
111[CR][LF][CR][LF]ABC[CR][LF][CR][LF]A[CR][LF][CR][LF][CR][LF][CR][LF]
222[CR][LF][CR][LF]DEF[CR][LF][CR][LF][CR][LF][CR][LF]R[CR][LF][CR][LF]
333[CR][LF][CR][LF]GHI[CR][LF][CR][LF]A[CR][LF][CR][LF][CR][LF][CR][LF]
444[CR][LF][CR][LF]JKL[CR][LF][CR][LF]A[CR][LF][CR][LF] [CR][LF][CR][LF]
[CR][LF][CR][LF] [CR][LF]
You would need a second macro to process these emails, extract the responses and update the DB. There is no validation on the user’s system but they are not being asked to do anything complicated. If you telephone and harangue them every time you get an incomplete reply, they will soon realise life is more pleasant if they get it right first time.
I do not know how difficult it is to access your DB from VBA but I do not believe anything else is particularly difficult.
This is not the approach you requested but I believe this will be very much easier to implement. More importantly, all the code is on your system which will make development and maintenance so much easier.

An automated email response system to incoming faxes

This is a theoretical question but any specific technical knowledge that could help will also be appreciated.
I am an IT Assistant with not much knowledge in programming (apart from EasyPattern and super-simple batch files) but have been given an opportunity to start getting into it by having been given a task to create a step in our document management system which is vaguely defined by the title of this question.
CONTEXT:
So, we have incoming faxes with short digit codes on them, these code correlate to identifying information in our database (relevantly; email addresses). In a watched folder environment we have software that upon auto-acknowledging these fax/image files being dropped into a designated incoming location (from a fax server) it initiates Microsoft Digital Imaging (MODI, runs in the background) to find these codes (using OCR, Optical Character Recognition) and places them into CSV files (one .csv file per code per fax page). Our database admin assures me that he can have the email addresses that correlate to the codes automatically placed into their correlating csv file.
GOAL:
It is from this point that I am being asked to find a way to have a universal unchanging email message ("We have received your fax") automatically sent to those email addresses. Upon a "way" being known, I am then to actually accomplish it.
QUESTION:
How to do this? As I said, a valid theoretical answer will suffice, for that will tell me how it can be done, which would in turn tell me what to learn, which would in turn tell me where to look.
WHERE I'M AT NOW:
I understand VBA to be a programming model within an 'event-driven' paradigm and that VBA programming projects are possible and supported in both Microsoft Outlook and Access. Does herein lie my answer? Can VBA used to accomplish this? (maybe auto import the email addresses from the csv file into the "To:" field of a outgoing email?) I'm hoping it'll be easier since the message can always stay the same (something along the lines of: We received your message). I'm reading two text books that introduce the reader to VBA in Access with one, and VBA in Outlook with the other.
I hope this message makes sense, this whole question might be naive, incoherent, or maybe even outright ignorant. But any patient and understanding response would be GREATLY appreciated.
You want something like this.
For posterity's sake, here is a summary of what it entails:
In Outlook, add a handler for the Application-level NewMailEx event.
Load each MailItem by its EntryID and handle it appropriately.
You would create your new email with Application.CreateItem(oMailItem), define its subject/body/recipients and then send it.

Programmatic Reaction to Receiving New Email

I'm interested in automating some reactive work I do when receiving certain emails in one of my email accounts. What I would like to have happen is:
On receipt of new email in the account
If the new email passes the "Need to React" criteria (based on body content and subject line)
3a. Scrape some content out of the email body and subject lines
3b. Populate a template form (e.g. Excel spreadsheet) with the scraped data
3c. Print the populated form and save the populated form in some folder (e.g. as a pdf)
What's the best (defined as easiest to implement by myself) approach / combination of technologies for achieving this automation?
i have not done exactly what you are asking, but I know Microsoft Outlook has a Rules engine that can take incoming messages, check for various content, and then do various actions including running applications and/or scripts.
You should look at Visual Studio Tools for Office if you are a c# person.
http://msdn.microsoft.com/en-us/vsto/default
You can write an Outlook add-on that can do pretty much everything you have outlined above.