Jump to content

Where to start for my first autoit project - accessing Outlook emails - (Moved)


Recommended Posts

Good Day All,

I have been searching high and low for a solution to a project I need to develop for one of my customers. I am confident that AutoIT and Water's Outlook UDF will help me achieve what I  need to do. Here is a point form of what I require:

  • Open Outlook
  • Look for all new email items with a specific value in the subject line
  • Open the email and retrieve the body of the email (It will be in HTML)
  • I need to extract a new email address from the first few lines of the email body
  • Once I have found a valid email address, I need to create a new email with the recipient being the email address address I extracted
  • I then need to populate the subject line with the subject line from the original email
  • I also need to remove the first 3 - 4 lines from the body of the original email and copy it to the body of the new email
  • I then need to send the new email
  • Lastly, I need to move the original new email to a processed folder

 

Does the above sound like something AutoIT with the Outlook UDF can do? 

I found this link (https://www.autoitscript.com/forum/topic/187631-open-mails-from-outlook-based-on-subject/) that shows how to open an email based on the specific subject line. So I am confident that at least I can do the first few requirements.

Is there a way to extract the email body and parse the first few lines to get the required email address? Is there a way to modify the body HTML to remove the first few lines? Will I be able to insert the modified HTML body into the new email?

Thanks in advance for any replies I receive.

Be well

Link to comment
Share on other sites

  • Developers

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I'm quite sure this can be done using the OutlookEX UDF.
As a qick start:

  • Open Outlook
    Use function _OL_Open
  • Look for all new email items with a specific value in the subject line
    Use _OL_ItemFind and select mails by using the unread and subject properties
  • Open the email and retrieve the body of the email (It will be in HTML)
    Specify this properties to be returned when calling _OL_ItemFind
  • I need to extract a new email address from the first few lines of the email body
    Search the array element returned by _OL_ItemFind that holds the body
  • Once I have found a valid email address, I need to create a new email with the recipient being the email address address I extracted
    _OL_ItemCreate, _OL_ItemRecipientAdd
  • I then need to populate the subject line with the subject line from the original email
    Pass this property to _OL_ItemCreate
  • I also need to remove the first 3 - 4 lines from the body of the original email and copy it to the body of the new email
    Modify the Body property returned by _OL_ItemFind and pass the result to _OL_ItemCreate
  • I then need to send the new email
    _OL_ItemSend
  • Lastly, I need to move the original new email to a processed folder
    _OL_ItemMove

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi Again. I've been able to get a start on the code but I was wondering how I can tell the code to look at a specific Inbox. I have 2 Inboxes and the emails I need to search for are in 1 of the Inboxes.

Thanks,

Yale

Link to comment
Share on other sites

You need to make a design decision before you start coding.

Do you want to process mails

  • as soon as they arrive (event driven)
  • only when you run your script

This decision greatly affects the structure of your script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi Water,

Sorry I was busy for a few days on another project. To answer your question, only when I run the script.

I have playing with some of your examples and with a sample example I found from March , 2017 where you gave someone some pointers.

What I have so far is - modified from your sample _OL_ItemSearch.au3

Global $oOutlook = _OL_Open()
Global $sString1 = "Order", $sString2 = "approval"
Global $aSearchArray[3][4] = [[2, 4],["subject", 2, $sString1, "and"],["subject", 2, $sString2, ""]]
Global $aItems = _OL_ItemFind($oOutlook, "*\Inbox", $olMail, "", "Subject", $aSearchArray, "Subject", "", 1

For the 2nd line, I need to search for "Order" and "approval" in the subject line. I have verified that there is 1 email in my InBox that has both Order and approval in the subject line but nothing gets returned. Do I have the SearchArray line set up incorrectly?

Thanks,

Yale

Link to comment
Share on other sites

First: Always check @error after calling a function to make sure it worked as expected
Second: You have to call function _OL_ItemSearch not _OL_ItemFind to accept an array as parameter.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

A very big ask for a first project!

It *CAN* be done as water has pointed out.

A heads up:

  • Do not mix your objects, arrays, and strings. Know when you are accessing pointers to an object, and when you are accessing the contents.
  • Most arrays are zero based. Often the zero index contains a count. This can trip you up in loops, with subscript out of range errors. Use _ArrayDisplay liberally for debugging. Comment it out as you get that part of your code under control. You can always uncomment it later if a later step proves troublesome.
  • Name your variables to be self descriptive. $string1 as a global variable is not going to help two thousand lines down.
  • Use lots of comments in your code. Drop hints to yourself for what you are trying to do.
  • ConsoleWrite is your friend for debugging. Even if you don't incorporate error processing into your project from the word go (dangerous), at least write out the return codes for each step to the console, along with where you are up to, and the value of the variable you are processing.
  • For processing efficiency, when doing a search for items in the $Outlook object, make it as narrow as possible as soon as possible.

As you have done, the best way to get help here is to show what you have done, and where you are stumbling. Everybody will jump in with hints and solutions.

Edited by Confuzzled
Link to comment
Share on other sites

Thanks for the pointer Water - its giving me what I expected. Thanks for the heads up tips Confuzzled. I am really liking the AutoIT product and the Outlook au library. 

Have a good night.

 

Link to comment
Share on other sites

:) 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...