This page (revision-1) was last changed on 20-Apr-2024 11:53 by UnknownAuthor

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
20-Apr-2024 11:53 3 KB UnknownAuthor

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 1 added 65 lines
[{PageViewPlugin}]
[Emergency Situation Sharing Tool]
!!!Abstract
GMAILを使ってEMAILをアプリケーションから出そうとしていました、相当に苦労しています。できるかな。
!!!Topics
!!Googleの正式なドキュメントを探しておこう
|Google APIなるものがある。コンソール[4]から使う。Gmail APIもある[5].
!!Javaでは?
|クイックスタート[6]試してみる。ラベルのリストを取るだけだったら手順に従えば、割とうまくいく。
|[8]を参考にメールの送信にチャレンジ。build.gradleのdependencyにcompile 'javax.mail:mail:1.4.7'の追加を忘れずに。
|mailを送るとなるとSCOPEを変えないといけない。うまくやらないと以下のメッセージが出続ける
{{{
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Insufficient Permission",
"reason" : "insufficientPermissions"
} ],
"message" : "Insufficient Permission"
}
}}}
|[6]で示されるGmailQuickstart.javaのソースの中にも書いてあるのだが、If modifying these scopes, delete your previously saved credentials/ folder.をやらないといけない。具体的には、tokensフォルダの中のStoredCredentialというバイナリファイルを消すと、Oauthをやり直すことになり、SCOPEが更新される。初めてGMAIL APIによるメール送信に成功!!!
!!Androidでは?
->[Send Message by Gmail in Android]
!!Firebaseでは?
|よし、サーバを経由しよう。よって、何らかの方法でサーバにメッセージを送って保存して、それをEMAILでサーバからアプリに配信しよう。
|[Firebase]のサンプル見つけた[2]これに従ってやっていると。。。なんと、SPARKプランだと外部APIをたたけないのは知っていたが、Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictionsというメッセージが。。。GMAILもたたけないのか。
{{{
I/System.out: exception = javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtS
534-5.7.14 NZNrXO6WopLLkOsOviYc4hjQ7KaqvazAk0w0FQ1fInDZZ4go32nP5RzQ0ci2tufzg55y7n
534-5.7.14 rvN9GSNRDZF3NWwoGINBDdk-na3YqEue0CENoQNdLDm2mTKb8-WkPpgqrwTLQnLmRe5mEr
534-5.7.14 cY2Xr2ql5AjBZ3SPNT3_DLKJPRypwOhC7kmcZqVVeDVA2rDAj35H1IH7oupX2pOie07Cvr
534-5.7.14 B-xy7jfkx7XBmjjfkLF5EQEOVnCwhzJi55UsPuF-mvTGPBHFbl> Please log in via
534-5.7.14 your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 11-v6sm6040618pfq.43 - gsmtp
finish sending email
}}}
|I do not know why but the error message was changed. Still does not work.
!!Node.jsでは?
|[Node.js]を使って送れるか試してみよう。ここ[3]を参照。Google APIの登録など途中まではうまくいったが、getLabel.jsを実行するあたりで下記のエラーがでて止まる。。。
{{{
(node:12764) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getRoot' of undefined
at list (gmail\node_modules\googleapis\build\src\apis\gmail\v1.js:529:31)
at list (internal/util.js:230:26)
at main (gmail\getLabels.js:31:28)
at <anonymous>
(node:12764) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:12764) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
}}}
|after then, I tried this example[7], and successfully got Label list. Then how can I send message!? I will try.
!!!reference
#[#2]Google, Send Confirmation Emails with Cloud Functions, [https://github.com/firebase/functions-samples/tree/master/email-confirmation]
#[#3]のびすけ, 2018.02.21, Google公式ライブラリを利用してNode.jsからGmailの送受信をしてみよう, [https://dotstud.io/blog/gmail-api-from-nodejs/]
#[#4]Google APIs, [https://console.developers.google.com/]
#[#5]Google, Gmail API, 2018年1月, [https://console.developers.google.com/apis/library/gmail.googleapis.com]
#[#6]Google, 2018年8月, Java Quickstart, [https://developers.google.com/gmail/api/quickstart/java]
#[#7]Google, 2018年8月, Node.js Quickstart, [https://developers.google.com/gmail/api/quickstart/nodejs]
#[#8]Google, 2017年5月, Sending Email, [https://developers.google.com/gmail/api/guides/sending]