【 Cloud 】Node.js 透過 Gmail 發送信件
內容
- 學習目標
- 前置準備作業
- 啟用 Gmail SMTP
學習目標
- 如何在
Node.js透過Gmail SMTP寄送信件
前置準備作業
- 已安裝 Node.js
- 已建立 Gmail
- 已於電腦端安裝 IDE,本範例使用 Visual Studio Code
Gmail 連線設定
Step 1. 登入 Google Account
Step 2. 設定兩階段認識
- 點選左邊的
Security

- 開啟
2-Step Verification設定頁面

- 點選
GET STARTED

- 輸入密碼後點選
Next

- 點選
CONTINUE取得驗證碼

- 點選
SEND( 本範例透過接收手機簡訊取得驗證碼 )

- 輸入驗證碼後點選
NEXT

- 點選
TURN ON

- 兩階段認證啟用完成

Step 3. 取得 App password
- 回到設定首面並點選
App passwords

- 輸入密碼後點選
Next

- 產生 App 密碼
Select app欄位: 點選Other (Custom name)


- 設定可識別的名稱

- 點選
GENERATE

- 記下此裝置的密碼

Node.js 透過 Gmail SMTP 發送信件
Step 1. 初始化專案
npm init -y Step 2. 安裝套件
npm i nodemailer Step 3. 撰寫程式
Step 4. 執行程式
node send-email-from-gmail.js Step 5. 查看結果
