Sendgrid: メール一括送信 (Sendgrid: Send Bulk Emails)
SendGrid でメールを送信します。
Configs
  • C1: API Key *
  • C2: 送信元のメールアドレス *
  • C3: 送信元の表示名
  • C4: テンプレート ID *
  • C5: 送信用データを設定したテーブル型データ *
Script (click to open)

main();
function main(){
  const tempId = configs.get("Template");
  const fromAddress = configs.get("FromAddress");
  const dynamicTemp = engine.findDataByNumber(configs.get("DynamicTemp"));
  const dyTempData = engine.findDataDefinitionByNumber(configs.get("DynamicTemp"));
  const fromName = configs.get("FromName");
  let subData;
  const json = {
    "personalizations": [
      
    ],
    "from": {},
  };
  json["template_id"] = tempId;
  json["from"]["email"] = fromAddress;
  if(fromName !== "" && fromName !== null){
    json["from"]["name"] = fromName;
  }
  if(dynamicTemp === null){
    throw "the table data is empty.";
  }
  const tableSize = dynamicTemp.size();
  const destinationLimit = 200;
  const subdataLimit = 50;
  if(tableSize > destinationLimit){
    throw "number of destination mail addresses can't be over " + destinationLimit + ".";
  }
  if(dynamicTemp.getRow(0).size() > subdataLimit){
      throw "number of subdata can't be over " + subdataLimit + ".";
    }
  for(i=0;i<tableSize;i++){
    json["personalizations"][i] = {
        "to": [{}],
        "dynamic_template_data": {},
      };
    if(dynamicTemp.get(i,0) === "" || dynamicTemp.get(i,0) === null){
      throw "Destination mail address is empty.";
    }
    json["personalizations"][i]["to"][0]["email"] = dynamicTemp.get(i,0);
    if(dynamicTemp.getRow(0).size() > 1){
      if(dynamicTemp.get(i,1) !== "" && dynamicTemp.get(i,1) !== null){
        if(dynamicTemp.get(i,1).search(/[;\,]/) !== -1){
          throw "invalid character is included in the destination name";
        }
        json["personalizations"][i]["to"][0]["name"] = dynamicTemp.get(i,1)
      }
      for(j=2;j<dynamicTemp.getRow(0).size();j++){
        subData = dyTempData.getSubDataDefinitions()[j].getName();
        if(subData !== "" && subData !== null){
          json["personalizations"][i]["dynamic_template_data"][subData] = dynamicTemp.get(i,j);
        }
      }
    }
  }
 const response = httpClient.begin()
    .bearer(configs.get("Key"))
    .body(JSON.stringify(json),"application/json; charset=UTF-8")
    .post("https://api.sendgrid.com/v3/mail/send");

  const status = response.getStatusCode();
  const responseTxt = response.getResponseAsString();
  if (status >= 300) {
    const error = "Failed to send \n status:" + status + "\n" + responseTxt
    throw error;
  }
  engine.log(status);
  engine.log(responseTxt);
}

Download

2020-12-29 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/sendgrid-mail-bulk-send/
Addonファイルのインポートは Professional でのみご利用いただけます

Notes

  1. C5はテーブル型データ項目です。1つの送信先につき1行を使用します。
  2. 1列目には各送信先のメールアドレスを、2列目には送信先で使用される送信先の表示名を、3列目以降はSendGridのテンプレートで使用されている埋め込み用文字列に代入する文字列を指定します。
  3. 3列目以降のサブデータ項目の名前は、埋め込み文字列として使用されている文字列({{Text}}を使用しているなら「Text」)と同じにしてください。埋め込み文字列が、サブデータ項目の値に置換されます。
  4. 1列目と2列目のサブデータ項目名は、任意の名前で構いません。

Capture

%d人のブロガーが「いいね」をつけました。