GitHub Actionsの処理結果をメールで通知する: Gmailの使用
概要 GitHub Actionsの処理結果をメールで通知する機会がありましたので、その備忘録です。 今回はGmailを使います。以下が参考になりました。 https://stackoverflow.com/questions/69947109/sending-email-with-github-actions Gmailの設定 以下に記載があります。2段階認証を有効にして、アプリパスワードを作成します。 https://github.com/dawidd6/action-send-mail?tab=readme-ov-file#gmail アプリパスワードの設定例は以下です。 ローカルでの動作確認 actを使って、ローカル環境でGitHub Actionsを実行します。 https://github.com/nektos/act あるリポジトリで以下のようなファイルを作成します。 name: Notification Workflow on: [push] jobs: send-mail: runs-on: ubuntu-latest steps: - name: Send mail if: success() # この行はデプロイが成功した場合にのみメールを送信するようにします uses: dawidd6/action-send-mail@v3 with: server_address: smtp.gmail.com server_port: 465 username: ${{secrets.MAIL_USERNAME}} password: ${{secrets.MAIL_PASSWORD}} subject: Deployment Completed - ${{ github.repository }} to: ${{secrets.MAIL_TO}} from: ${{ secrets.MAIL_FROM }} body: | Hello, The deployment process for the repository ${{ github.repository }} has been successfully completed. Commit: ${{ github.sha }} Commit link: https://github.com/${{ github.repository }}/commit/${{ github.sha }} Branch: ${{ github.ref }} Best regards, ${{ secrets.MAIL_FROM }} 以下のようなコマンドでシークレットを使うことができました。 ...
