1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

IBM Cloud Functions を使って 5 分おきにメールを送信する

Last updated at Posted at 2020-07-16

Email Delivery, powered by Sendgrid を使う

こちらのサービスを使ってメールを送信します。
IaaS を有効化済みのアカウントをお持ちであれば、25000 通まで無料の「Free Package」を活用できます。

Email Delivery, powered by Sendgrid - IBM Cloud : https://cloud.ibm.com/catalog/infrastructure/email-delivery
image.png

貼り付けた画像_2020_07_16_23_01.png

GitHub からダウンロード

GitHub にあるファイルをダウンロードします。


git clone https://github.com/khayama/fn-sendEmail.git
cd fn-sendEmail

今回の Functions デプロイ用 yaml では以下のように定義しています。
Functions 実行パラメータは、環境変数の値を取得して埋め込む形で定義しています。

sendEmail.yml

packages:
  sendEmail_package:
    version: 1.0
    license: Apache-2.0
    actions:
      sendEmail:
        version: 1.0
        description: sendEmail with SL_USER, SL_APIKEY
        docker: openwhisk/dockerskeleton
        function: sendEmail.sh
        inputs:
          SL_USER: $SL_USER
          SL_APIKEY: $SL_APIKEY
          TO: $TO
          FROM: 
                default: no-reply@ibmfunctions.com
          SUBJECT: 
                default: test subject
          BODY: 
                default: test body

    triggers:
      every5minutes:
        feed: /whisk.system/alarms/alarm
        inputs:
          cron: "*/5 * * * *"

    rules:
      sendEmail-every5minutes:
        description: Action is triggered every 5 minutes
        action: sendEmail
        trigger: every5minutes

環境変数セット

以下のように環境変数をセットします。

IaaS API key の発行・取得


export SL_USER="xxx"
export SL_APIKEY="xxx"
export TO="宛先メールアドレス"

Functions デプロイ


ibmcloud fn deploy --manifest sendEmail.yml
# 削除するには ibmcloud fn undeploy --manifest sendEmail.yml

動作確認

5 分おきの定期トリガーの後に、「sendEmail」のアクションが正常に実行されていることが確認できます。

https://cloud.ibm.com/functions/dashboard

Kobito.046HzO.png

受信メール

こんな感じです。

貼り付けた画像_2020_07_16_17_03.png

参考

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?