I'm bit new to google app script and try figure out how to resolve my google mail problem with google app script
Update : only particular attachment need to be remove rest of the structure and attachment need to same. provided solution remove all the attachments !
Problem :
I daily get email with pdf attachments from my vendors and clients some are send to me using automatic systems and some from manual some of this email has attachment called "noname" which I cant open or read. I'm using automated application to download this pdf attachments when there is "noname " attachment that email fully ignored so I miss some pdf daily
Planed Solution :
using google app script I'm try to capture the "noname" attachment and delete only that file rest of the email content and pdf need to be same .
I have manage to implement code to capture specific email which send noname attachment and if they unread then check attachments and delete noname
Where I need advice : how to delete selected attachment ??
function myFunction() {
Logger.log("unread emails: " +
GmailApp.search('is:unread from:[email protected]'));
var deta = GmailApp.search('is:unread from:[email protected]')
var msgs = GmailApp.getMessagesForThreads(deta);
for (var i = 0 ; i < msgs.length; i++) {
Logger.log("msg object lenth " + msgs.length)
for (var j = 0; j < msgs.length; j++) {
Logger.log("msg i object lenth " + msgs[i].length)
var attachments = msgs[i][j].getAttachments();
var m_id = msgs[i][j].getId()
for (var k = 0; k < attachments.length; k++) {
Logger.log("attachment lenth " + attachments.length)
Logger.log('Message "%s" contains the attachment "%s" (%s bytes)', msgs[i][j].getSubject(), attachments[k].getName(), attachments[k].getSize());
if (attachments[k].getName() == "noname" ){
// attachments[k].deleteAttachment();
Logger.log('Message "%s" contains the attachment "%s" (%s bytes)', msgs[i]
[j].getSubject(), attachments[k].getName(),attachments[k].getSize());
}
}
}
}
}