特定のパラメータセットに対してGmailにネイティブなフィルタを作成します。Google Appsスクリプトを使用してGmailにネイティブフィルタを作成します。
基本的には、Googleの別名機能を多く使用しています(電子メールの後に+記号が付きます)。私は、 "To"行を読み込んで "+"を探すフィルタを作成するプロセスを自動化したいと思います。 "+"が見つかった場合は、 "+"の後ろのラベルを作成します。次に、専用の/ネイティブフィルタを作成します。受信トレイをスキップし、 "+"の後ろのラベルを適用します。
Gmailのスクリプトを見て、ネイティブフィルタを作成する方法が見つかりませんでした。私はこの機能が実装されたばかりであることを理解しています。
function getTo() {
// Log the To line of up to the first 50 emails in your Inbox
var email = Session.getActiveUser().getEmail();
Logger.log(email);
var threads = GmailApp.getInboxThreads(0, 50);
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
Logger.log(messages[j].getTo()||email);
}
}
}
助けがあれば助かります。
ソリューション:
// Creates a filter to put all email from ${toAddress} into
// Gmail label ${labelName}
function createToFilter(toAddress, labelName) {
// Lists all the filters for the user running the script, 'me'
var labels = Gmail.Users.Settings.Filters.list('me')
// Search through the existing filters for ${toAddress}
var label = true
labels.filter.forEach(function(l) {
if (l.criteria.to === toAddress) {
label = null
}
})
// If the filter does exist, return
if (label === null) return
else {
// Create the new label
GmailApp.createLabel(labelName)
// Lists all the labels for the user running the script, 'me'
var labelids = Gmail.Users.Labels.list('me')
// Search through the existing labels for ${labelName}
// this operation is still needed to get the label ID
var labelid = false
labelids.labels.forEach(function(a) {
if (a.name === labelName) {
labelid = a
}
})
Logger.log(labelid);
Logger.log(labelid.id);
// Create a new filter object (really just POD)
var filter = Gmail.newFilter()
// Make the filter activate when the to address is ${toAddress}
filter.criteria = Gmail.newFilterCriteria()
filter.criteria.to = toAddress
// Make the filter remove the label id of ${"INBOX"}
filter.action = Gmail.newFilterAction()
filter.action.removeLabelIds = ["INBOX"];
// Make the filter apply the label id of ${labelName}
filter.action.addLabelIds = [labelid.id];
// Add the filter to the user's ('me') settings
Gmail.Users.Settings.Filters.create(filter, 'me')
}
}
おかげで、エンダー
今すぐあなたの受信トレイを実行しますか?メールが届くのは?これまでにどのようなコードを試しましたか? – Brian
だから私はそれがまだ頻繁にフィルタリングされていない新しい電子メールを探すために実行したい。ネイティブフィルタは常に実行されている必要があります。高度な機能でいくつかのフィルタ設定が見つかりました:https://developers.google.com/gmail/api/v1/reference/users/settings/filters –
私は.getToをテストしています。私は私の電子メールとチェックする電子メールの違いを排除しようとしています。違いはラベルになります。それから私はラベルを持っていれば、私はフィルタを作るだろう。私はまだフィルタを作ろうとしていません。 –