应用配方
在 Duaer 里把 Gmail 附件自动存到 Google Drive
在 Duaer 里,带附件的新邮件一到,就把每个附件按原文件名上传到 Google Drive 的指定文件夹。
在 Duaer 里搭附件归档
- 加 Gmail Trigger,关掉 Simplify,在 Options 里打开 Download Attachments;Filters 的 Search 写 has:attachment。
- 附件会放在 attachment_0、attachment_1 …… 上。接 Code,粘贴下面的代码,一个附件一条,文件都放在 data 上。
- 只要 PDF 时接 If,条件 {{ $json.fileName.toLowerCase().endsWith('.pdf') }} 为 true。
- 接 Google Drive,Resource 选 File,Operation 选 Upload,Input Data Field Name 填 data,File Name 填 {{ $json.fileName }},选 Parent Drive 和 Parent Folder。
- 发布数字组织。
const out = [];
for (const item of $input.all()) {
for (const key of Object.keys(item.binary ?? {})) {
out.push({
json: { ...item.json, fileName: item.binary[key].fileName },
binary: { data: item.binary[key] },
});
}
}
return out;按发件人或月份分文件夹
File Name 可以带上日期,例如 {{ $now.toFormat('yyyy-MM') }}-{{ $json.fileName }}。要真正分文件夹,先用 Google Drive 的 Folder 创建操作建好,再把 Parent Folder 改成表达式。
常见问题
Duaer 会重复保存同一封邮件的附件吗?
不会。Duaer 的 Gmail Trigger 每封新邮件只触发一次;手动重跑旧执行时才会再传一遍。
Duaer 能存企业邮箱或 QQ 邮箱的附件吗?
能。把 Gmail Trigger 换成 Email Trigger (IMAP),打开下载附件,后面的 Duaer 步骤不变。
同组
节点
在 Duaer 里用 Google Drive 上传文件
在 Duaer 里,Google Drive 默认 Authentication 是 OAuth2,Resource 是 File,Operation 是 Upload。Input Data Field Name 默认 data。需要 googleDriveOAuth2Api 凭据。
节点在 Duaer 里用 Gmail 发邮件
在 Duaer 里,Gmail 默认 Authentication 是 OAuth2,Resource 是 Message,Operation 是 Send。Email Type 默认 HTML。需要 gmailOAuth2 凭据。
数据在 Duaer 里处理文件和图片
理解并使用 Duaer 里的二进制数据。
报错在 Duaer 里解决 Google 凭证 invalid_grant 和 7 天失效
Duaer 里 Gmail、Google Sheets、Google Drive 凭证用了几天就报 invalid_grant,多半是 Google 应用还在 Testing 状态。发布应用,再重新连接凭证。