
開始: Microsoft 365 Outlook for Business: メール受信時
Start: Microsoft 365 Outlook for Business: Email Received
このアイテムは、Outlook が新しいメールを受信すると、プロセスを開始します。
Basic Configs
- 工程名
- メモ
Configs for this Auto Step
- conf_OAuth2
- C1: OAuth2 設定 *
- conf_Category
- C2: カテゴリ *
- conf_idData
- C3: メール ID を保存するデータ項目 *
- conf_timestampData
- C4: 受信時刻を保存するデータ項目
- conf_rfc822msgIdData
- C5: RFC 822 Message-ID ヘッダを保存するデータ項目
Notes
- Microsoft 365 の Outlook for Business で使用できるモデリング要素です
- 個人用の Outlook では使用できません
- デフォルトのカテゴリ、ユーザが作成したカテゴリのいずれかを指定できます
- ルールを作成することで、新着メールに自動的にカテゴリを付与することができます
- 定期的に Questetra BPM Suite から Outlook にポーリングが行われ、新着メールがないかチェックされます
- 新着メールがあれば、プロセスが開始されます
- 初回のチェック時には、プロセスは開始されず、チェックのみ行われます
- チェックの状況は、プロセスログより確認できます
- 短時間に多数のメールを受信すると、全てのメールについて、プロセスは開始されません
- 目安は、15 分間で 90 プロセスです
Capture

See Also
Script (click to open)
- 次のスクリプトが記述されている XML ファイルをダウンロードできます
- outlook-message-received.xml (C) Questetra, Inc. (MIT License)
- Professional のワークフロー基盤では、ファイル内容を改変しオリジナルのアドオン自動工程として活用できます
// OAuth2 config sample at [OAuth 2.0 Setting]
// - Authorization Endpoint URL: https://login.microsoftonline.com/{your-tenant-id}/oauth2/v2.0/authorize
// - Token Endpoint URL: https://login.microsoftonline.com/{your-tenant-id}/oauth2/v2.0/token
// - Scope: https://graph.microsoft.com/Mail.Read offline_access
// - Consumer Key: (Get by Microsoft Azure Active Directory)
// - Consumer Secret: (Get by Microsoft Azure Active Directory)
const DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX";
const OUTLOOK_MESSAGE_LIST_LIMIT = 1000; // 取得上限数
/**
* configs から必要な情報の取り出し
* @returns {Object} setting 設定
* @returns {AuthSettingWrapper} setting.auth HTTP 認証設定
* @returns {String} setting.category カテゴリ名
*/
const prepare = () => {
const auth = configs.getObject('conf_OAuth2');
const category = configs.get('conf_Category');
return {
auth,
category
};
};
/**
* 追加されたメールの検索
* @param {Number} limit 取得上限数
* @param timestampLowerLimit timestamp の下限
* @returns {Array} messages メッセージ一覧
* @returns {string} messages[].id Message ID
* @returns {timestamp} messages[].timestamp メール受信時刻
* @returns {string} messages[].rfc822msgId RFC 822 Message-ID
*/
const list = (limit, timestampLowerLimit) => {
const {auth, category} = prepare();
const messages = getMessages(auth, category, limit, timestampLowerLimit);
logMessages(messages);
return messages;
};
/**
* メッセージ一覧のログ出力
* @param {Array} messages メッセージ一覧
*/
const logMessages = (messages) => {
const replacer = (key, value) => value instanceof java.sql.Timestamp ? dateFormatter.format(DATETIME_FORMAT, value) : value;
messages.forEach(msg => engine.log(JSON.stringify(msg, replacer)));
};
/**
* Microsoft Graph API にメール一覧取得の GET リクエストを送信し、メッセージ一覧を返す
* @param {String} auth 認証設定
* @param {String} category カテゴリ名
* @param {Number} limit 取得上限数
* @param timestampLowerLimit timestamp の下限
* @returns {Array} messages メッセージ一覧
* @returns {string} messages[].id メール ID
* @returns {timestamp} messages[].timestamp メール受信時刻
* @returns {string} messages[].rfc822msgId RFC 822 Message-ID
*/
function getMessages(auth, category, limit, timestampLowerLimit) {
limit = Math.min(limit, OUTLOOK_MESSAGE_LIST_LIMIT); // limit のほうが小さくなるはずだが、念のため
const query = `receivedDateTime ge ${dateFormatter.format('UTC', DATETIME_FORMAT, timestampLowerLimit)} and categories/any(c:c eq '${category}')`;
const response = httpClient.begin().authSetting(auth)
.queryParam('$top', `${limit}`)
.queryParam('$select', 'id,receivedDateTime,internetMessageId')
.queryParam('$orderby', 'receivedDateTime DESC')
.queryParam('$filter', query)
.get('https://graph.microsoft.com/v1.0/me/messages');
const status = response.getStatusCode();
const responseStr = response.getResponseAsString();
if (status !== 200) {
engine.log(responseStr);
throw `Failed to get messages. status: ${status}`;
}
const messages = JSON.parse(responseStr).value;
if (messages.length === 0) {
// 該当メッセージが無い
engine.log('no messages');
return [];
}
return messages
.filter(msg => !engine.isProcessStarted(msg.id)) // 既にプロセス開始済みのものを除く
.map(msg => {
return {
id: msg.id,
timestamp: dateFormatter.parse(DATETIME_FORMAT, msg.receivedDateTime),
rfc822msgId: msg.internetMessageId
};
});
}
