Jump to content

Recommended Posts

Posted

@TheXman Both are getting error 11. I checked with other gmail account after signing out and re logging with new one. Same error coming thru code, but with atom url manually, it works

Posted (edited)

Let's try a different method.  Make sure that you update the $USERNAME & $PASSWORD constants with the correct values.

#include <Constants.au3>

test()

Func test()
    ;Put your USERNAME and PASSWORD below
    Const $USERNAME = "username", _
          $PASSWORD = "password"

    Local $oComErr = ObjEvent("AutoIt.Error", com_error_handler)

    With ObjCreate("winhttp.winhttprequest.5.1")

        ;Set up and send request
        .Open("GET", "https://mail.google.com/mail/feed/atom", False)
        .SetCredentials($USERNAME, $PASSWORD, 0)
        .Send()

        If .Status <> 200 Then Exit MsgBox($MB_ICONWARNING, "WARNING", _
                                           "BAD HTTP RESPONSE" & @CRLF & @CRLF & .Status & " " & .StatusText)

        ;Display response
        ConsoleWrite(StringLeft(.ResponseText, 200) & @CRLF) ;First 200 bytes of response

    EndWith

EndFunc

Func com_error_handler($oComErr)
    Local $sErrMsg

    With $oComErr
        $sErrMsg =  @CRLF
        $sErrMsg &= ">>>  COM ERROR  <<<" & @CRLF
        $sErrMsg &= StringFormat("Script Line Number : %s", .ScriptLine) & @CRLF
        $sErrMsg &= StringFormat("HRESULT            : 0x%x (%s)", .Number, .Number) & @CRLF
        $sErrMsg &= StringFormat("Windows Error      : %s", StringStripWS(.WinDescription, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("Object Description : %s", StringStripWS(.Description, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("GetLastError()     : %s", .LastDllError) & @CRLF
    EndWith

    ConsoleWrite($sErrMsg)
    
    MsgBox($MB_ICONERROR, "ERROR", $sErrMsg)

    Exit
EndFunc

 

Edited by TheXman
Slightly modified the script
Posted (edited)

@thexman I tried the above code and ended with a  message  "BAD HTTP RESPONSE : 401 Unauthorized"    -  at the same time manually atom url is working.   The surprise is I got a mail from google security alert that "Someone just used your password to try to sign in to your account from a non-Google app. Google blocked them, but you should check what happened. Review your account activity to make sure no one else has access."   

What should I do to solve this?

Edited by Jahar
Add extra information
Posted (edited)
3 minutes ago, Jahar said:

 I changed google settings to allow less secure apps and it worked well with your last code.

:thumbsup:

Since it worked with your browser, I was going to suggest trying to use a valid browser User-Agent before lowering the Google security setting.  But if that works for you, great!  ;)

Edited by TheXman
Posted

@TheXman  I have an issue with response text received with the code. I am having a mail with subject "You've received" - but response text gives "You&#39;ve received " . Please help me to solve this.

#include <Constants.au3>

test()

Func test()
    ;Put your USERNAME and PASSWORD below
    Const $USERNAME = "username", _
          $PASSWORD = "password"

    Local $oComErr = ObjEvent("AutoIt.Error", com_error_handler)

    With ObjCreate("winhttp.winhttprequest.5.1")

        ;Set up and send request
        .Open("GET", "https://mail.google.com/mail/feed/atom", False)
        .SetCredentials($USERNAME, $PASSWORD, 0)
        .Send()

        If .Status <> 200 Then Exit MsgBox($MB_ICONWARNING, "WARNING", _
                                           "BAD HTTP RESPONSE" & @CRLF & @CRLF & .Status & " " & .StatusText)

        ;Display response
        ConsoleWrite(StringLeft(.ResponseText, 200) & @CRLF) ;First 200 bytes of response

    EndWith

EndFunc

Func com_error_handler($oComErr)
    Local $sErrMsg

    With $oComErr
        $sErrMsg =  @CRLF
        $sErrMsg &= ">>>  COM ERROR  <<<" & @CRLF
        $sErrMsg &= StringFormat("Script Line Number : %s", .ScriptLine) & @CRLF
        $sErrMsg &= StringFormat("HRESULT            : 0x%x (%s)", .Number, .Number) & @CRLF
        $sErrMsg &= StringFormat("Windows Error      : %s", StringStripWS(.WinDescription, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("Object Description : %s", StringStripWS(.Description, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("GetLastError()     : %s", .LastDllError) & @CRLF
    EndWith

    ConsoleWrite($sErrMsg)
    
    MsgBox($MB_ICONERROR, "ERROR", $sErrMsg)

    Exit
EndFunc

 

Posted

I have an issue with response text received with the code. I am having a mail with subject "You've received" - but response text gives "You&#39;ve received " . Please help me to solve this.

#include <Constants.au3>

test()

Func test()
    ;Put your USERNAME and PASSWORD below
    Const $USERNAME = "username", _
          $PASSWORD = "password"

    Local $oComErr = ObjEvent("AutoIt.Error", com_error_handler)

    With ObjCreate("winhttp.winhttprequest.5.1")

        ;Set up and send request
        .Open("GET", "https://mail.google.com/mail/feed/atom", False)
        .SetCredentials($USERNAME, $PASSWORD, 0)
        .Send()

        If .Status <> 200 Then Exit MsgBox($MB_ICONWARNING, "WARNING", _
                                           "BAD HTTP RESPONSE" & @CRLF & @CRLF & .Status & " " & .StatusText)

        ;Display response
        ConsoleWrite(StringLeft(.ResponseText, 200) & @CRLF) ;First 200 bytes of response

    EndWith

EndFunc

Func com_error_handler($oComErr)
    Local $sErrMsg

    With $oComErr
        $sErrMsg =  @CRLF
        $sErrMsg &= ">>>  COM ERROR  <<<" & @CRLF
        $sErrMsg &= StringFormat("Script Line Number : %s", .ScriptLine) & @CRLF
        $sErrMsg &= StringFormat("HRESULT            : 0x%x (%s)", .Number, .Number) & @CRLF
        $sErrMsg &= StringFormat("Windows Error      : %s", StringStripWS(.WinDescription, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("Object Description : %s", StringStripWS(.Description, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("GetLastError()     : %s", .LastDllError) & @CRLF
    EndWith

    ConsoleWrite($sErrMsg)
    
    MsgBox($MB_ICONERROR, "ERROR", $sErrMsg)

    Exit
EndFunc

 

Posted (edited)

Why did you start another topic with the exact same question?

 

Edited by TheXman
  • Moderators
Posted

You need to show some patience. Just because this is the most important thing in the world to you does not mean you just spam the forum until you get an answer. Forum etiquette is to wait 24 hours before bumping your thread.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted (edited)

The advice you were given a year ago is still true today.  Please stop @ tagging me.  I am done trying to help you until you start actually "showing" some of your own efforts.  Don't show me my unmodified code that I provided to help you and ask for additional code because it does not do exactly what you need it to do.  What have you done to try to resolve your issue?  Show me your code (or a representative example) that you have modified or created yourself and ask specific questions about issues or obstacles that you are encountering.

 

Edited by TheXman
Posted

It was a pleasure!  I look forward to doing it again.  ;)

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
  • Recently Browsing   0 members

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