Developers Jos Posted March 9, 2021 Developers Posted March 9, 2021 @tonycstechapps or should I say @tonycst or @tonycst2 or .... whatever .... you are banned. 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.
ElChupakanibre Posted March 12, 2021 Posted March 12, 2021 This process explained in https://developers.google.com/gmail/api/guides/uploads UDF is not specific on what type of upload user is requesting. There are 3 types one of which is media. Changing type of email from $oHttp.Open("POST", "https://www.googleapis.com/gmail/v1/users/" & _URIEncode($sEmailAdress) & "/messages/send", False) to $oHttp.Open("POST", "https://www.googleapis.com/gmail/v1/users/" & _URIEncode($sEmailAdress) & "/messages/send?uploadType=media", False) helps but not 100%. My personal computer has no problem sending pictures while Work computer (with all the antivirus, firewalls and other garbage) still randomly misses one or another in no particular order. Does anybody have a solution ? Thanks in advance. If $Evolution=True Then Why ($Human worse then $Animal) ;? EndIf
queensoft Posted September 23, 2022 Posted September 23, 2022 (edited) On 9/11/2019 at 4:06 AM, antalgu said: Hello, does anyone know how to get the info returned from the function gmailUsersMessagesList I was just trying it out and got that there was no error in the execution of the function, but i wasn't able to retrieve the information i wanted afterwards. It's strange because I thought the array returned from the function was 2D, but when asked for any on the elements it contained i got this error (2nd image), and if i treated it as if it was only 1D the MsgBox text would just appear to be blank. SOLUTION FOUND, SEE BELOW!! I have the exact same problem: Local $aRet = gmailUsersMessagesList($sYourGmailAdress, $aToken, "Bearer", False, 'IMPORTANT') Result is an array, containing these records - _ArrayDisplay($aRet): Array (2D array with message and thread IDs) 0 = no other pages 18 = 18 messages with label IMPORTANT Then I continue with _ArrayDisplay($aRet[0]) and I get 18 records, all arrays But, if I want to display some records, I get error for any of those two commands: _ArrayDisplay($aRet[0][0]) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aRet = ' & $aRet[0][0] & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: _ArrayDisplay($aRet[0][0]) _ArrayDisplay(^ ERROR At the same time, UBound($aRet[0]) is 18, which is correct, there are 18 messages with label IMPORTANT. And all those 18 records are arrays, right ??? SOLUTION : _ArrayDisplay(($aRet[0])[0]) - and I get a simple 2 records array, with message and thread IDs: And in order to get each record Message Id - (($aRet[0])[$i])[0], Thread Id - (($aRet[0])[$i])[1] Edited September 24, 2022 by queensoft
argumentum Posted September 23, 2022 Posted September 23, 2022 53 minutes ago, queensoft said: At the same time, UBound($aRet[0]) is 18, which is correct, there are 18 messages with label IMPORTANT. And all those 18 records are arrays, right ??? You can add arrays in arrays like Matryoshka dolls Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
queensoft Posted September 23, 2022 Posted September 23, 2022 (edited) Yes, I know, I know both things. But so far I have only used 1D and 2D arrays, with simple (integer / string) values. Never array inside array. And I didn't know how to access the values of the "smaller doll" inside the "big doll" !! But I have found the solution and edited my original post. Thanks. Edited September 23, 2022 by queensoft argumentum 1
queensoft Posted September 24, 2022 Posted September 24, 2022 (edited) SOLUTION FOUND, SEE BELOW!! Now I have another problem - cannot read email message: $ret01 = gmailUsersMessagesGet((($aRet[0])[$i])[1], $aToken, "Bearer", "full") Everything up to that point is working perfectly: oauth, access token, refresh token, send email, gmailUsersLabelsList, get Thread ID I have added multiple scopes to oauth/project, as per this: https://developers.google.com/gmail/api/reference/rest/v1/users.messages/get I have renewed and refreshed authorization (oAuth2GetAuthorizationCode, oAuth2GetAccessToken, oAuth2RefreshAccessToken). Error is this: +++ Line: 479, Func: gmailUsersMessagesGet() -> Error durning send request to Google. $oHttp.Status = 401 $oHttp.ResponseText = { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "errors": [ { "message": "Login Required.", "domain": "global", "reason": "required", "location": "Authorization", "locationType": "header" } ], "status": "UNAUTHENTICATED", "details": [ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "CREDENTIALS_MISSING", "domain": "googleapis.com", "metadata": { "method": "caribou.api.proto.MailboxService.GetMessage", "service": "gmail.googleapis.com" } } ] } } Again, all other operations are working perfectly: send email, get labels list, get list of messages with specific label (gmailUsersMessagesList) SOLUTION : I was missing a parameter - $sYourGmailAdress: $ret01 = gmailUsersMessagesGet((($aRet[0])[$i])[1], $sYourGmailAdress, $aToken, "Bearer", "full") Edited September 24, 2022 by queensoft
queensoft Posted September 25, 2022 Posted September 25, 2022 This is definitely a bug. Not in the actual Gmail/Oauth code, but in the JSON code. gmailUsersLabelsList function output for custom labels: { "id": "Label_1", "name": "[Imap]/Sent", "type": "user" }, { "id": "Label_14", "name": "[Imap]/Trash", "type": "user" }, { "id": "Label_6866461006926381418", "name": "testxxx", "type": "user" } Func _JsonValue from oAuth.au3 will stop at first ] and will not read some of the labels. Can anyone please fix the RegEx to read all labels? In the mean time, I think I will just use _StringBetween to extract all Label IDs. Thanks
NassauSky Posted October 14, 2023 Posted October 14, 2023 (edited) Anyone try sending an attachment using this UDF? My script does send the pdf file but it comes out damaged on the receiving end. Maybe some kind of encoding has to be done to the file. If so does anyone know how to correct this? $pdfFilePath = @ScriptDir & "\SampleEmail.pdf" gmailUsersMessagesSend("tet@test.org", _ "My Document Scan", _ "Please see attached document scanned. This email does not accept replies back.", _ "noreply@mysite.org", _ $sAccessToken, _ "Bearer", _ Default, _ $pdfFilePath) Edited October 14, 2023 by NassauSky
Andreik Posted October 15, 2023 Posted October 15, 2023 (edited) @NassauSky Not sure about this UDF but @Jos's UDF works pretty nice with Gmail and attachments. Edited October 15, 2023 by Andreik
queensoft Posted October 15, 2023 Posted October 15, 2023 Looks like sending PDF is a problem: https://answers.microsoft.com/en-us/windows/forum/all/windows-live-mail-corrupting-pdf-files-when/55728c50-d17d-42a6-ab12-05e6d6918847 https://developers.google.com/gmail/api/guides/uploads I was unable to find a solution, tried several Content-Type stuff. I'm a complete noob about this.
NassauSky Posted October 15, 2023 Posted October 15, 2023 @Andreik it seems that using that UDF probably needs less secure app access and I didn't want to do that. @queensoft maybe we'll get some someone experienced with this taking a look.
Andreik Posted October 15, 2023 Posted October 15, 2023 It depends what do you understand by less secure application. It's true that you have to turn off that setting but it doesn't mean you are using plain http and insecure connections but a less secure access to account according to Google security standards.
NassauSky Posted October 15, 2023 Posted October 15, 2023 @Andreik interesting I never looked into the details but there have been quite a few warnings when I used that for an account in the past.
queensoft Posted October 15, 2023 Posted October 15, 2023 8 minutes ago, NassauSky said: @Andreik it seems that using that UDF probably needs less secure app access and I didn't want to do that. @queensoft maybe we'll get some someone experienced with this taking a look. I'm using the script with Oauth authorization (client ID, secret code, refresh code....) I don't think I have "less secure app" enabled in Google for the script / app.
NassauSky Posted October 15, 2023 Posted October 15, 2023 @queensoft yeah this current thread uses that technique. I'm hoping someone has a solution using this method. @Andreik has an alternative solution but just want to clearly confirm if it's safe in gmail when I disable secure app access.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now