Jump to content

Recommended Posts

Posted (edited)
  • Gmail API send email
;=======================================================================================================================
; Date:             2018-02-12, 17:52
;
; Description:      Send email using API to single or group of receipients.
;
; Function(s):      gmailUsersMessagesSend() -> example usage
;
; Param(s):         $sClientId          Your client_id from *json file
;                   $sClientSecret      Your client_secret from *json file
;                   $sRefreshToken      Refresh token received from oAuth2GetAccessToken()[2]
;                   $sYourGmailAdress   You gmail email adress
;                   $aRecipient         Receipients: can be single without array or sepatared by comma "email1,email2"
;                   $sSubject           Message Subject.
;                   $sBody              Message body in text
;                   $sBodyHtml          Message body in Html
;                   $sAttachment        Attachment: string or array | Put path to file ex. [@ScriptDir & "\test.png"]   
;=======================================================================================================================

#Include <Gmail API.au3>

Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" 
Local $sClientSecret = "cWalvFr3WxiE6cjUkdmKEPo8"
Local $sRefreshToken = "34wSsq5sdfcoH-Rl-dfldfLffqxq2fhdPL1K-sf"
Local $sYourGmailAdress = "youremail@gmail.com"
Local $aRecipient = ["friend1@gmail.com", "friend2@yahoo.com"]
Local $sSubject = "Testing Gmail API with Autoit"
Local $sBody = "Hello there. Just testing..." & @CRLF
Local $sBodyHtml = '<meta charset="utf-8"><h2>AutoIt v3<br></h2>'
Local $sAttachment = Default

Local $aToken = oAuth2RefreshAccessToken($sRefreshToken, $sClientId, $sClientSecret)

If Not IsArray($aToken) Then
    except("<none>", "Failed to get access token. Exiting..", 1)
    Exit
EndIf

$aToken = $aToken[0]

Local $aRet = gmailUsersMessagesSend($aRecipient, $sSubject, $sBody & $sBodyHtml, $sYourGmailAdress, $aToken, "Bearer", Default, $sAttachment)

If Not IsArray($aRet) Then
    except("<none>", "Failed to send an email.", 2)
EndIf

ConsoleWrite("Message Sent Sucessfully!" & @CRLF)
ConsoleWrite("MessageId: " & $aRet[0] & @CRLF)
ConsoleWrite("ThreadId: " & $aRet[0] & @CRLF)

Local $aLabelsIds = $aRet[2]
ConsoleWrite("Sent message labels_ids: " & @CRLF)

For $sLabel = 0 To UBound($aLabelsIds) - 1
    ConsoleWrite("Label: " & $aLabelsIds[$sLabel] & @CRLF)
Next

 

Edited by Ascer
Posted (edited)

please add this lines to each of your file:
 

#AutoIt3Wrapper_Run_AU3Check=Y
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

and check what will happen when you try to use Au3Check by pressing CTRL+F5 in SciTe4AutoIt .

ps.
Currently there are still few bugs.... and warnings.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@mLipok

Thanks for verify this. It's my first time when i hear about #AutoitWrapper. 

This tool help me so much in next UDF. 

Bugs fixed, UDF updated. (CTRL + F5 show me nothing)

Posted (edited)
  On 2/17/2018 at 6:55 AM, Ascer said:

Bugs fixed, UDF updated. (CTRL + F5 show me nothing)

Expand  

But I get this:
 

  Reveal hidden contents

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 4 weeks later...
Posted
  On 2/19/2018 at 7:06 AM, Ascer said:

Its' because you use a new Scite. I don't see this warrings on version 3.5.4

Expand  

No, no, it means that you still have bad habits and you do things in the wrong way.
Try a little more to fight with this.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 6 months later...
Posted
  On 10/11/2018 at 9:28 PM, argumentum said:

I looked at the code and the variable is used. How can I fix this ?

Expand  

It's not used correctly, the Ternary operator doesn't return a value, so assigning it to one is pointless. Remove all variable references used with the Ternary operator anywhere you see something like this:

$bQuestion = IsArray($aEmailAdress)     ?   _TableInsert($aTable, $aEmailAdress[0])         :   _TableInsert($aTable, "")

Also remove the variable declaration because $bQuestion isn't used anywhere that it is needed.

 

Second, don't declare variables conditionally like this:

If IsArray($sRemoveLabelIds) Then
        Local $iUbound = UBound($sRemoveLabelIds)

Declare the variable, then assign something to it inside the If statements. Don't declare it twice depending on whether the If statement is valid

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)
  On 10/11/2018 at 10:15 PM, BrewManNH said:

Also remove the variable declaration because $bQuestion isn't used anywhere that it is needed.

Expand  

error: Statement cannot be just an expression.

I have no idea why the ternary is needed or how to go about it  =/
Would you recode that line ?, thank
s @BrewManNH.

Use if/then/else

Edited by argumentum
answered my silly question

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • Developers
Posted
  On 10/12/2018 at 11:51 AM, mBild said:

Great work... However, all line breaks are missing in the text body... What am I doing wrong?

Expand  

Welcome and nice to see you think we are clairvoyant. ;)

Seriously, post what you are trying so we can see what you are doing. Might have something to do with an HTMLbody but that is guessing.

Jos 

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.
  :)

Posted
  On 10/12/2018 at 12:24 PM, Jos said:

Welcome and nice to see you think we are clairvoyant. ;)

Seriously, post what you are trying so we can see what you are doing. Might have something to do with an HTMLbody but that is guessing.

Jos 

Expand  

Many thanks for your quick reply and sorry, for being unclear.

I am using FileRead to get text (with linebreaks) from a .txt file (ANSI) to a variable. The text should then be automatically emailed using your UDF. When I output the variable in the console all works fine. If I add it as text body ($sBody) and email it, the text is all correct, however all line and paragraph breaks are missing? Am I missing something?               

Many thanks for your support... 

Posted

$hFile = Fileopen($a_FileList[1][0], $FO_ANSI)
$FileContent = FileRead($hFile)
FileClose($hFile)

 

ConsoleWrite($FileContent)

--> All correct with line and paragraph breaks

 

 

; Function(s):      gmailUsersMessagesSend() -> example usage

Local $sBody = $FileContent & @CRLF 

Local $sBodyHtml = Default
Local $sAttachment = Default

---> Email is send without line and paragraph breaks

 

 

Many thanks for your help!!!

 

Posted

just guessing...

Do you send $sBody or $sBodyHtml ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Thanks for the reply.

I send $sBody, but also with $sBodyHtml there are no line and paragraph breaks in the email body?

 

Maybe I am missing something?

  • Developers
Posted (edited)

Well, I am still not seeing any runable script so have no idea as I can't test unless I am going to spend time to code it myself.

Jos

Edited by Jos

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.
  :)

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
×
×
  • Create New...