Jump to content
nooneclose

[SOLVED] how to find outlook emails that are unread and have a specific subject

Recommended Posts

Good morning everyone, I thought I had already solved this issue but it turns out I did not. 

My code finds unread emails with this specific subject line of "request" but when I change the subject to SKIPPED + "request" = ("SKIPPED request") the program still finds the email and tries to process it. I only want to process emails with the exact match subject of "request".

Here is my code that "finds" the unread emails with the subject of "request" or so I thought. 

Func ListUnreadEmails()

    ;*******************************************************************************
    ; Lists all unread E-mails from the folder Outlook-UDF-Test
    ;*******************************************************************************
    ; Stores all the unRead emails into an array
    Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _
    "[UnRead]=True", "Subject", "request", "EntryID,Subject", "", 1)

    ; Displays the array of unRead emails
    If IsArray($aItems) Then
        ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails")

    Else
        MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _
        "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended)
    EndIf

    ; Gets the number of unread emails
    Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1
    ;MsgBox("", "Number of Unread emails", $numberOfUnRead)

EndFunc

It acts as if any part of the subject containing the word "request" and the email is unread that it will try to process it. (I think)

Edited by nooneclose

Share this post


Link to post
Share on other sites

Thats correct, it's a partial match so you can't do what you want with _OL_ItemFind.
With function _OL_ItemSearch it's possible to search for unread mails that start with a specific string in the subject - unfortunately it is quite complex.

I suggest to use _OL_ItemFind to retrieve all unread mails, then search the returned array for all mails with the needed subject and ignore the rest.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@water thank you for the quick reply. I was able to fix the issue with a simple if statement. 

 

; Retrieve the items object
    Global $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default)
    $oItem.GetInspector

    Global $eBody          = $oItem.Body                        ; The Body of the email
    Global $eSenderAddress = $oItem.SenderEmailAddress          ; Customers email address
    Global $eSentOn        = $oItem.SentOn                      ; When was the email sent?
    Global $eSubject       = $oItem.Subject                     ; Subject of the email

    if $eSubject <> "Request" Then
        ChangeEmailStatus()
    EndIf
    
Func ChangeEmailStatus()

    ;*******************************************************************************
    ; changes the status of an email from Unread to Read
    ;*******************************************************************************
    ConsoleWrite("Current email has been changed from Unread to Read." & @CRLF)
    _OL_ItemModify($oOutlook,$aItems[1][0], Default, "Unread=False")

EndFunc

I inserted an if statement to force the program to "skip" (mark as read) the emails with subjects that do not match. Thank you very much for your time. 

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

  • Similar Content

    • By v120
      Rapid Fire Mouse Hack Script
      *snip*
       
    • By cdeb
      As for the object, in this case the StringReplace() function does not work for me.
      These are my steps:
      1) Extract the subject from an EML file.
       (the first character is an emoji )
      source from EML file: 
      $sSubject = "?utf-8?B?8J+TiCA1IG9mIHRoZSBCZXN0IFN0b2NrcyB0byBCdXkgZm9yIERlY2VtYmVy?=" 2) in this case I perform a decoding with _QuotedPrintable_DecodeEncodedWord()
      output is: 
      $sSubject = "?? 5 of the Best Stocks to Buy for December"  
      3) I perform StringReplace():
      $sSubject = StringReplace($sSubject, "??", "") or
      $sSubject = StringReplace($sSubject, Chr(63)&Chr(63), "")  
      But the characters ?? they are not replaced.
       
      Yet if I make an Asc of every character of the string with a for loop, are the first two characters really? that is 63
      For cycle
              Local $aArray = StringSplit($sSubject, "", $STR_NOCOUNT)         For $i = 0 To UBound($aArray)-1             ConsoleWrite($aArray[$i] & " - " & Asc($aArray[$i])& @CR)         Next Output:        
      ? - 63
      ? - 63
        - 32
      5 - 53
        - 32
      o - 111
      f - 102
        - 32
      t - 116
      h - 104
      e - 101
        - 32
      Does anyone have an explanation of why it doesn't work?
      Thank you all
       
    • By water
      Extensive library to control and manipulate Microsoft Outlook.
      Theads: Development - General Help & Support - Example Scripts - Wiki
      There is another UDF (OutlookTools) available (as a beta at the moment) to import/export contacts and events to VCF/ICS files.
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2019-11-30)
      None
    • By nooneclose
      Good morning, I am trying to figure out if it is possible to check if these invoice lines exist or not. 
      Here are the table and column name: INVOICELINE.INVOICELINENUM (a required field if created)
      Here is a picture of what I am talking about. (Do not worry about security. the picture is from a demo test site so all information is fake)
       
      is there any way to check if these fields exist or not? (they do not exist unless the user clicks on "New Row")
      Example: line 11 does not exist right now. How would I go about to see if it did or not? 
      This is what I have so far:
      SELECT DISTINCT iv.invoicenum, iv.description FROM invoice AS iv JOIN invoiceline AS ivl ON iv.invoicenum = ivl.invoicenum AND iv.siteid = ivl.siteid /* = 'nothing' and yet somehow not null? */ WHERE iv.invoicenum NOT IN (SELECT invoicelinenum FROM invoiceline WHERE invoicelinenum IS NOT NULL) I get 0 results where I should get more than 0. 
    • By Kruxe
      Hello Everyone,
      I am very green when it comes to AutoIT, I have recently started using it to automate a job that i perform using MS Excel and that is working great. Recently I have been faced with a challenge I which i need to copy a specific set of lines from one .txt file and past them, overwriting a specific set of lines in a different .txt file. I honestly have no clue how I can copy the specified lines and transfer them. What functions / commands could I use and how could I lay them out I AutoIT? Any and all help will be appreciated. 
      Thanks!
      Kruxe
×
×
  • Create New...