PoojaKrishna

want to check gmail account for new mails and read content.

29 posts in this topic

Hi friends,

 

I want to create a script than can read a gmail inbox to see content of mails from a particular address. I have searched a lot in the forum, there are so many topics related to this but I was not able to get a script that reads mail text. Can anyone please help?

Share this post


Link to post
Share on other sites



Moved to the proper forum; not sure why people can't figure out what the Examples forum is for, even when we put "DO NOT post Help and Support Questions here" at the top.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Extremely sorry for posting in the example forum. Clicked the [create new topic] button while reading the example forum.

Share this post


Link to post
Share on other sites

I use IMAP and stunnel (for SSL) and works well...

Share this post


Link to post
Share on other sites

Thank you for your reply, can you please help in getting the details on how to use it? Link to any posts regarding this?

Please help.

Share this post


Link to post
Share on other sites

Hey my friend.  I don't have an auto it script to give you, but I have a powershell script which does just that.  Just note that the account CANNOT have dual authentication enabled and needs to be configured to work with "less secure apps".  If you can convert it to autoit for your own purposes, hey, its all yours.  Things to note:

use port 587

SMTP server is smtp.gmail.com

your user name for the credentials is your gmail address EXCLUDING the "@gmail.com" portion.

sendgmail.zip

Share this post


Link to post
Share on other sites

Thank you MattHiggs. I'm checking your code. Will let you know if I can make progress.

Share this post


Link to post
Share on other sites

MattHiggs,

I think your script is for sending mails. I'm trying to make a script to read mails in inbox.

Share this post


Link to post
Share on other sites

However, if you want a solution that does the what you want and one that you yourself don't have to write, I would check out the program "Howard" at this website.  Its a freeware utility that does exactly what you want and I know I am a satisfied user

Share this post


Link to post
Share on other sites

After logging into Gmail, you can access your RSS Atom Feed, it feeds your unread emails.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Thank you Decoder, but we can not read the mail content from atom Feed.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;#RequireAdmin
#include <string.au3>


Global $eReturn = _CheckMail("username", "password")
Global $Emails = @extended

Switch @error
    Case 0
        Switch @extended
            Case True
                msgbox(0,"", $Emails & " mail read")
                ConsoleWrite("   0>"&$eReturn[0][0] & @CR)
                ConsoleWrite("   "& $Emails & " " & $eReturn[0][1] & @CR)
                For $x = 1 To $Emails
                    ConsoleWrite("!>Title   - " & $eReturn[$x][0] & @CR)
                    ConsoleWrite("+>Name    - " & $eReturn[$x][1] & @CR)
                    ConsoleWrite("->Email   - " & $eReturn[$x][2] & @CR)
                    ConsoleWrite(">summary - " & $eReturn[$x][3] & @CR & @CR)
                    msgbox(0,"", $eReturn[$x][3])
                Next
            Case Else
                MsgBox(64,"success!","Success! But you have no new emails :(")
        EndSwitch
    Case 1
        MsgBox(0,"Error!","Couldn't get your new emails for some reason...")
    Case 2,3
        MsgBox(0,"Error!","you need to enter an user name and password!")
    Case 4
        MsgBox(16,"Error!","Error Getting URL Source!")
    Case 5
        MsgBox(16,"Error!","No response?")
    Case 6
        MsgBox(16,"Error!","Unauthorized access, possibly a wrong username or password!")
EndSwitch

; #FUNCTION# ====================================================================================================================
; Name ..........: _CheckMail
; Description ...: Checks a Google Email for new emails.
; Syntax ........: _CheckMail($UserName, $Pswd[, $UserAgentString = ""])
; Parameters ....: $UserName            - An unknown value.
;                 $Pswd             - An unknown value.
;                 $UserAgentString   - [optional] An unknown value. Default is "".
; Return values .: A 2d array with email information as follows~
;                   1|Title
;                   2|Name
;                   3|Email
;                   4|Summary
;                   5|Date
;                   6|Time
;
; Author ........: dantay9
; Modified ......: THAT1ANONYMOUSDUDE
; Remarks .......:
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/topic/111853-gmail-email-checker/page__view__findpost__p__819409
; Example .......: Yes
; ===============================================================================================================================

Func _CheckMail($UserName, $Pswd, $UserAgentString = "")
    If Not $UserName Then Return SetError(2,0,0)
    If Not $Pswd Then Return SetError(3,0,0)
    If $UserAgentString Then HttpSetUserAgent($UserAgentString)
    Local $source = InetRead("https://" & $UserName & ":" & $Pswd & "@gmail.google.com/gmail/feed/atom",1)
    If @error Then
        ConsoleWrite("!>Error Getting URL Source!" & @CR & "     404>@Error =" & @error & @CR & "    404>@Extended =" & @extended & @CR)
        Return SetError(4,0,0)
    EndIf
    If $source Then
        $source = BinaryToString($source)
    Else
        Return SetError(5,0,0)
    EndIf
    If StringLeft(StringStripWS($source, 8), 46) == "<HTML><HEAD><TITLE>Unauthorized</TITLE></HEAD>" Then  Return SetError(6, 0, 0)
    If Not Number(StringBetween($source, "<fullcount>", "</fullcount>")) Then Return SetError(0,0,0)
    Local $Email = _StringBetween($source, "<entry>", "</entry>")
    If @error Then Return SetError(1, 0, 0)
    Local $Time
    Local $Count = UBound($Email)
    Local $Datum[$Count + 1][6]
    $Datum[0][0] = StringBetween($source, "<title>", "</title>")
    $Datum[0][1] = StringBetween($source, "<tagline>", "</tagline>")
    For $i = 0 To $Count - 1
        $Datum[$i+1][0] = StringBetween($Email[$i], "<title>", "</title>")
        If Not $Datum[$i+1][0] Then $Datum[$i][0] = "(no subject)"
        $Datum[$i+1][1] = StringBetween($Email[$i], "<name>", "</name>")
        $Datum[$i+1][2] = StringBetween($Email[$i], "<email>", "</email>")
        $Datum[$i+1][3] = StringBetween($Email[$i], "<summary>", "</summary>")
        $Time = StringBetween($Email[$i], "<issued>", "</issued>")
        $Datum[$i+1][4] = DateFromTimeDate($Time)
        $Datum[$i+1][5] = TimeFromTimeDate($Time)
    Next
    Return SetError(0,$Count,$Datum)
EndFunc
Func StringBetween($Str, $S, $E)
    Local $B = _StringBetween($Str, $S, $E)
    If @error Then Return SetError(1,0,0)
    Return SetError(0,0,$B[0])
EndFunc   ;==>StringBetween

; #FUNCTION# ====================================================================================================================
; Name ..........: DateFromTimeDate
; Description ...: Returns email sent date.
; Syntax ........: DateFromTimeDate($String)
; Parameters ....: $String            - A gmail date string
; Return values .: None
; Author ........: ???
; Example .......: No
; ===============================================================================================================================

Func DateFromTimeDate($String)
    Local $RegEx = StringRegExp($String, "(?<Year>d{2}|d{4})(?:-)(?<Month>d{1,2})(?:-)(?<Day>d{1,2})", 1)
    If IsArray($RegEx) Then
        Return Int($RegEx[0]) & "/" & Int($RegEx[1]) & "/" & Int($RegEx[2])
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>DateFromTimeDate

; #FUNCTION# ====================================================================================================================

; Name ..........: TimeFromTimeDate
; Description ...: Returns the email sent time.
; Syntax ........: TimeFromTimeDate($String)
; Parameters ....: $String            - An unknown value.
; Return values .: None
; Author ........: ???
; Example .......: No
; ===============================================================================================================================

Func TimeFromTimeDate($String)
    Local $RegEx = StringRegExp($String, "(?<Hour>d{1,2})(?::)(?<Minute>d{1,2})(?::)(?<Second>d{1,2})", 1)
    If IsArray($RegEx) Then
        Return (Int($RegEx[0]) - 4) & ":" & Int($RegEx[1]) & ":" & Int($RegEx[2]) ;don't know why I have to subtract 4
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>TimeFromTimeDate

 

Share this post


Link to post
Share on other sites

Is there any way to read the content of unread mails from outlook using, OutlookEX? I also would like to mark mails as read after processing.

Share this post


Link to post
Share on other sites

You would have to create a Global IE Object and login into gmail into that object before doing anything.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
29 minutes ago, PoojaKrishna said:

Is there any way to read the content of unread mails from outlook using, OutlookEX? I also would like to mark mails as read after processing.

Yes there is. Just have a look at functions _OL_ItemFind and _OL_ItemModify. The example scripts that come with the UDF explain how.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thank you so much.

 

I have tried the below code. The inbox has unread mails but still blank array returned.

#include <OutlookEX.au3>

; *****************************************************************************
; Create test environment
; *****************************************************************************
Global $oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)
;Global $Result = _OL_TestEnvironmentCreate($oOutlook)
;If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF - Manage Test Environment", "Error creating the test environment. @error = " & @error & ", @extended = " & @extended)
Global $aItems
;------------------------------------------------------------------------------------------------------------------------------------------------
; Example 4 - Get unread mails from a folder and all subfolders
;------------------------------------------------------------------------------------------------------------------------------------------------
$aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, "[UnRead]=True", "", "", "Subject,Body", "", 1)

If IsArray($aItems) Then
    _ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind Example Script - Unread mails")
Else
    MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended)
EndIf

_OL_Close($oOutlook)

 

Share this post


Link to post
Share on other sites

Check the help file for _OL_ItemFind and you will see that parameter 2 needs to be the folder to check. So please try "*\Inbox".


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Tried, but didn't help.

#RequireAdmin
#include <OutlookEX.au3>

; *****************************************************************************
; Create test environment
; *****************************************************************************
Global $oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)
;Global $Result = _OL_TestEnvironmentCreate($oOutlook)
;If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF - Manage Test Environment", "Error creating the test environment. @error = " & @error & ", @extended = " & @extended)
Global $aItems
;------------------------------------------------------------------------------------------------------------------------------------------------
; Example 4 - Get unread mails from a folder and all subfolders
;------------------------------------------------------------------------------------------------------------------------------------------------
$aItems = _OL_ItemFind($oOutlook, "*\Inbox", $olMail, "[UnRead]=True", "", "", "Subject,Body", "", 1)

If IsArray($aItems) Then
    _ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind Example Script - Unread mails")
Else
    MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended)
EndIf

_OL_Close($oOutlook)

 

Share this post


Link to post
Share on other sites

This works:

#include <Array.au3>
#include <OutlookEX.au3>
$oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

$aFolder = _OL_FolderAccess($oOutlook, "", $olFolderInbox)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error accessing Inbox. @error = " & @error & ", @extended = " & @extended)

$aItems = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, "[UnRead]=True", "", "", "EntryID,Subject,Body", "", 1)

If IsArray($aItems) Then
    _ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind Example Script - Unread mails")
Else
    MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended)
EndIf
_OL_Close($oOutlook)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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

    • unity06
      By unity06
      Hi Forum,
      I currently want to write a script that will download the emails from my gmail account and store them on my hard drive in form of text messages. Text file name will have date followed by title of the email and the email body will be the text body. Then I will write my scripts to monitor and inspect emails and post process the data.
      Anyone can suggest an easy way to achieve this?
      Maybe it has to be done indirectly via first having an email client that tracks my gmail account and downloads emails to hard drive such as Outlook?
      Will be very thankful for any suggestions on how to tackle this.
      Regards
    • lewisg
      By lewisg
      Any suggestions as to how to download, get, or retrieve email from Google's Gmail?  No need to send mail only receive. 
      I thought perhaps JiBE's SSL UDF might work however a reply to a post at his original post says otherwise (Didn't want to hijack his post).
      I have been using "GAM", "GYB", and "GMAIL Backup"(old), all command line inputs. Running them through a AutoIT script using RUN() and RUNWAIT() works somewhat, but has been unreliable. 
       
    • JackWebb
      By JackWebb
      Hi Everyone!
       
      So I use Autoit to automate my logins. Gmail has recently made some changes to their login page that breaks my script. The username goes in okay, but not the password. I can type in the password manually and it's no problem. What I can't understand is how does the browser know the password is not being typed in manually? I tried every trick I could think of (i'm an Autoit noob) to simulate human typing. Using send() raw and slowing down the type rate of the keys. Nothing works, can anyone shed some light on this?
       
      #include <WinAPIShPath.au3> #include <Array.au3> Opt("SendKeyDelay", 25) Opt("SendKeyDownDelay", 25) Send("email@gmail.com", 1) sleep(1500) Send("{enter down}", 0) Send("{enter up}", 0) sleep(1500) Send("password", 1) sleep(1500) Send("{enter down}", 0) Send("{enter up}", 0)  
    • slaughter
      By slaughter
      Emails if is taken from other sources gmail account some times takes ages to arrive or you have very time to do it by yourself going in option and clicking "Check mail now"
      Solution is automated script witch does it for you while your pc is running.
      Has one problem
      ID of elements 'Check_mail_now' always changing so you have to adjust it, maybe someone can offer solution?
      At his moment it clicks on tow other accounts, but you can always add more.
       
      Sorry for posting maybe in wrong section, it is like an demo but needs some help Maybe admins can move topic to help section. Thanks.
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.8.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here $url1="https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/" $url2="https://mail.google.com/mail/u/0/?shva=1#settings/accounts" $email="xxx@gmail.com" $password="my password" $check_interval_min="2" $id_of_Check_mail_now1 = ":f42" $id_of_Check_mail_now2 = ":f46" #include <IE.au3> Local $oUser, $oPass, $oSubmit, $oInput $oIE = _IECreate ($url1,1,0) _IELoadWait($oIE) Local $oForm = _IEFormGetObjByName($oIE, "gaia_loginform") Local $input_username = _IEFormElementGetObjByName($oForm, "Email") _IEFormElementSetValue($input_username, $email) Local $input_userpass = _IEFormElementGetObjByName($oForm, "Passwd") _IEFormElementSetValue($input_userpass, $password) ConsoleWrite("form submit1."&@CRLF) Local $oSubmit = _IEGetObjByName($oIE, "signIn") _IEAction($oSubmit, "click") ;_IEFormSubmit($oForm) ConsoleWrite("form submit2."&@CRLF) _IELoadWait($oIE) Sleep(4000) ConsoleWrite("Login complete. Navignating to settings."&@CRLF) _IENavigate($oIE, $url2) _IELoadWait($oIE) Sleep(2000) While 1 $oDiv = _IEGetObjById($oIE, $id_of_Check_mail_now1) _IEAction($oDiv, "click") $oDiv = _IEGetObjById($oIE, $id_of_Check_mail_now2) _IEAction($oDiv, "click") Sleep($check_interval_min*1000*60) WEnd
    • PhoenixXL
      By PhoenixXL
      Remote Gmail UDF


      Working
      It uses the Google atom API to get the Summary of the mail,
      The Summary of the mail is enough to get a direct link or a single function with parameters
      Execute any Function (or Script) and get the Return Values in your E-mail

      Requirements
      Gmail (Email) Account A Remote Computer with Internet Access Representation

      Functions
      You can now use you Gmail account to use Autoit Functions in a remote computer Can execute a function through reading the email. Can Email back the return values of an executed function. The parameter can even be a variable present in the script [see Syntax] Execute a Script through Direct Link. Execute multiple scripts zipped together through Direct Link. Can Email back the PID of the running executables with the scripts. Attach any file and get it in your email. Able to send the multiple attachments zipped together. Writes all the return values in a Log file. No email is executed twice, the Message IDs are stored for this purpose. Future Updates
      Support single line nesting Get the attachment, to execute the script Syntax

      Syntax for Functions
      PXL<FuncName>: (<data type>)<first param part a>+(<data type>)<first param part b>|(<data type>)<secondparam>/PXL

      Colon[:] - Separation of Function Name with the Parameters
      Bar [ | ] - Separation of different parameters
      Plus [+] - To Concatenate Values
      PXL /PXL - The tags where the code is enclosed
      Brackets [ () ] - For specifying the type of the parameter

      DataTypes - Always Preceded by any parameter and are enclosed with brackets

      ; | (s) - String
      ; | (n) - Number
      ; | (f) - Floating Number
      ; | (i) - Integer
      ; | (b ) - Binary
      ; | (v) - Variable
      ; | (h) - Hex
      ; | (m) - macro
      ; | (w) - Handle
      ; | (p) - Pointer


      Syntax for Direct Links
      PXL<DirectLink>^<Type>/PXL

      PXL /PXL - The tags where the code is enclosed
      Caret [ ^ ] - To Separate the Link and the Type
      Type - Either Zip or au3

      DirectLink WebServer
      Some of webservers providing Direct Links
      DropBox [Tested - Recommended]
      Herosh [Tested]*
      FileToLink
      FileDen

      * DirectLink from Herosh changes therefore Example 4 wont work after a while

      Credits
      CaptainClucks - Atom Feed
      Jos - SMTP Mailer
      wraithdu - Zip UDF

      Change Log
      v1.0 - First Release
      v1.1 - Added Script Execution with Zipping Functionality
      v1.2 - Fixed some Minor bugs
      v1.3 - Added RemoteGmail_Startup
      v1.4 - Fixed Compiling Issues
      v1.5 - Added flexibility for execution of scripts from any email.

      The UDF - Download
      The UDF is currently tested on x86
      All Comments ,Queries , Feedback and Advice are welcomed...
      The UDF with the Examples have been compiled in the following Zip
      v1.5 RemoteGmail.7z
      Previous Downloads : 1119

      Regards
      Phoenix XL