I have script that can transfer email from gmail to gdrive and my plan is replace the filename of the email attachment to assigned filename with current date ddmmyy (Ex. project012322.xlsx) or .csv when the file is transferred to gdrive.
May I know what I need to modify or add with my script?
const searchItem = "in:inbox subject:(My Project) has:attachment";
const threads = GmailApp.search(searchItem, 0, 100);
const ids = threads.flatMap((thread) => {
const messages = thread.getMessages();
return messages.map((message) => {
const id = message.getId();
if (!values.includes(id)) {
const attachments = message.getAttachments({ includeInlineImages: false, includeAttachments: true });
attachments.forEach((attachment) => {
Drive.Files.insert({ title: attachment.getName(), mimeType: attachment.getContentType(), parents: [{ id: folderId }] }, attachment.copyBlob());
});
}
return [id];
});
});
Drive.Files.insert({ title: attachment.getName(), mimeType: attachment.getContentType(), parents: [{ id: folderId }] }, attachment.copyBlob());withtitle: attachment.getName()new Date()- use Utilities.formatDate(date, timeZone, format)