;======================================================================================================================= ; 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 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 = '

AutoIt v3

' Local $sAttachment = Default Local $aToken = oAuth2RefreshAccessToken($sRefreshToken, $sClientId, $sClientSecret) If Not IsArray($aToken) Then except("", "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("", "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