Что нового

Послать емайл успользуя OAuth Google Gmail API

tonycstech

Новичок
Сообщения
94
Репутация
3
Версия AutoIt
3.3.14.5
Версия
0.1
Источник https://www.autoitscript.com/forum/topic/192391-udf-google-oauth-20-with-autoit/
Было немного непонятно то я написал свои инструкции. И у них старый код и не работал 100%


Original post https://www.autoitscript.com/forum/topic/192391-udf-google-oauth-20-with-autoit/
It was somewhat confusing so i wrote my own. And they had outdated code so i wasnt even working 100%

Для тех у кого проблемы с закрытыми портами SMTP, можно послать емайл через гугл почту API
Для этого порты не нужны кроме 80го который итак открыт практичиески везде.
Для этого нужен гугл акоунт для почты понятное дело.


For those who have problems with closed SMTP ports, you can use OAuth, google Gmail API.
No ports needed for this to work except port 80 which is open pracically everywhere.
For that you need google account, for Gmail obviously.

Инструкции только на Англиском. Там нет Русского языка к сожалению. Если у кого есть там русский язык, то у меня почемуто нет. Понятия не имею почему поэтому что есть то есть.
Что не понятно обьюсню.

Instructions in English only.
1. Login to Gmail and go to
2. Create new project with what ever name you like.
Give it few seconds to process.
3. Navitage to OAuth concent screen from the menu on left and click CREATE
Fill in required fields and click NEXT
Don't add any SCOPES. Just click Continue.
Add your email as a user and click Continue
Go back to Dashboard
4. Go to Library and search for Gmail
Select and Enable it. It should take you to the Gmail API page.
5. Return to Dashboard click Credentials.
Click Create Credential and chose OAuth client ID
Type: Desktop app
Name: Your autoit project name that uses this API
Once created, you will be provided with Client ID and Client Secret
Save them somewhere.
6. Once Client ID is created,copy its ID and Secret to $sClientId and $sClientSecret variables inside "1 Get Access Code.au3" "2 Get Token.au3" and "3 Test.au3" files and save them.
7. Run "1 Get Access Code.au3"
It will open browser and ask you to login to your gmail accont which you use for this for this project.
Once logged it, continue through the warning page and select ALLOW when prompted.
Page will then show error but, look at the address bar and copy everything
between http://localhost/?code= and &scope=https://mail.google.com/
You can close the browser now.
8. Edit "2 Get Token.au3" file pasting copied code into $sAuthorizationCode variable
Run "2 Get Token.au3"
The refresh_token value is generated. Copy it.
9. Open "3 Test.au3" file and paste the token into $sRefreshToken variable.
Edit $sYourGmailAdress to put your email address you use for this project
Edit $aRecipient address to where you want to send email.
Save and run.
Verify email was sent.
Нужные UDF прикрепил. Читайде дальше.
Needed UDF's attached. Continue reading.

Проблемы: Иногда по каким то причинам, прикреплённый фото, почемуто не работает.
Как будто какая-то корупция происходит.
Сам текс емайла без проблем, а вот фото когда как.
Изходя из https://developers.google.com/gmail/api/guides/uploads я добавил тип и проблема вроде бы решилась.
Нужно редактировать Gmail API.au3 и поменять

Код:
$oHttp.Open("POST", "https://www.googleapis.com/gmail/v1/users/" & _URIEncode($sEmailAdress) & "/messages/send", False)

на
Код:
$oHttp.Open("POST", "https://www.googleapis.com/gmail/v1/users/" & _URIEncode($sEmailAdress) & "/messages/send?uploadType=media", False)

Придел 5МБ медиа файл
Это 100% решение проблемы но помогает в большенстве случаев.
Если отсылаете только что сделаный скриншот, то после скриншота дайте паузу на пару секунд на всякий случай.


Problems: Sometimes for some reasons attached image files dont work
Seems like some kind of random corruption takes place.
Need to edit Gmail API.au3 and make following changes
Код:
$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)

Media file size limit is 5MB
This is not 100% bulletproof but it does help.
If you take screenshot and emailing it, add small delay after taking it, like couple of seconds just in case.
 
Автор
Ascer,Tonycstech
Источник
Ссылка на источник

Вложения

  • 1 Get Access Code.au3
    209 байт · Просмотры: 9
  • 2 Get Token.au3
    839 байт · Просмотры: 9
  • 3 Test.au3
    2.7 КБ · Просмотры: 9
  • Gmail API.au3
    52.1 КБ · Просмотры: 11
  • oAuth.au3
    9.7 КБ · Просмотры: 9
Последнее редактирование:
Верх