LoginSignup
2
0

More than 1 year has passed since last update.

【SAP Cloud Integration】メールを送信する

Last updated at Posted at 2021-10-26

はじめに

この記事では、SAP Cloud Integrationを利用してメールを送信してみる、というシナリオを実装してみます。使用するのはGmailのメールサーバです。以下の点で苦労したので、記録に残しておきます。

  • Gmailの証明書の取得方法
  • 証明書をアップロードしても出るエラーの対処

関連記事
【SAP Cloud Integration】ODataサービスを呼ぶ

参考にした記事
SAP Cloud Integration(CPI): Customizing Email using Mail Adapter
こちらはOutlookでの設定です。

事前準備

GmailのユーザID、パスワードをSecurity Materialに登録

Security Materialのタイルをクリックします。
image.png
Create>User Credentailsを選択します。
image.png
GoogleアカウントのユーザID、パスワードを設定します。
image.png

Gmailの証明書をKeystoreに登録

TLSを使ってGmailのSMTPサーバと通信するために、Gmailの証明書を取得します。
証明書はこちらの記事を参考に取得しました。
https://kb.fortinet.com/kb/documentLink.do?externalID=FD40548
以下のように証明書の部分を切り取って、.cer形式で保存します。
image.png
Keystoreに証明書を登録します。
image.png
Add>Certificateより、ダウンロードした証明書を選択して追加します。
image.png
Connectivity Testsで接続テストをしておきます。
image.png
以下を設定して"Send"をクリックします。正常終了すればOKです。
image.png

項目 設定値
Host smtp.gmail.com
Authentication Plain User/Password
Credential Name <Security Materialに登録したCredentialの名前>

以下のようなエラーが出た場合は、メッセージの一番下に記載されているURLに従って対応します。
https://support.google.com/mail/answer/78754
image.png
2ステップの認証を使っていない場合(私の場合はそうでした)、以下を実行します。

Integration Flowの作成

以下のようなフローを作成しました。各ステップの設定は以降で説明します。
image.png

Start Timer

タイマーで起動する設定です。このフローはデプロイ時に一度だけ動きます。
image.png

Set Content

このステップはContent Modifierです。メールに添付ファイルをつけたいのでMessage Bodyにテキストを設定しています。
image.png

Mail Adapter

メール送信の設定です。

  • Connectionタブの設定 image.png
項目 設定値
Address smtp.gmail.com:587
Authentication Plain User/Password
Credential Name <Security Materialに登録したCredentialの名前>
  • Processingタブの設定 image.png
項目 設定値
From <自分のメールアドレス>
To 同上
Subject <メールの件名>
Body Mime-Type Text/Plain

添付ファイルをつける設定をします。
image.png

項目 設定値
Name <添付ファイルの名前>
Mime-Type Text/Plain
Source Body ※Content Modifierで設定したBodyをそのままテキストファイルにする

以上でフローの設定は完了です。保存、デプロイして動作を確認します。

動作確認

Monitor Message Processingのタイルを見ると、正常終了したことがわかります。
image.png
image.png
Gmailのメールボックスにメールが届きました。
image.png
添付ファイルもついています。
image.png

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0