Gmail filters only act on messages when they arrive. There's not a way to do what you want with filters.
For a pure Gmail solution, you can accomplish almost what you want by judicious use of search and the Canned Responses Lab. That will make sending identical messages to a bunch of people relatively easy.
Another option would be to use some third-party tool. You can get your email via POP3 or IMAP, so virtually any desktop email client can get your messages. There are probably tools out there that will allow you to do what you're looking for. (That's outside the ken of WebApps, though.)
Alternatively, what you really need is a Customer Relationship Management (CRM) solution. Salesforce.com and its ilk probably already have the tools that you want.
As Rubén pointed out, the format of sendEmail
method is different: the last parameter is an object of options such as {attachments: ...}
.
Also, images inserted in a spreadsheet via "insert image" are not associated with any cell in a sheet, they are just floating over the sheet. This makes them unsuitable for your purpose of matching images to recipients listed in the sheet.
Images via a URL
A way to associate images with cells is to use =image(url)
formula, which requires the image to be accessible somewhere. I suggest the following approach: put the URL itself in the column for attachment, say D, and =image(D2)
command elsewhere, just to have a preview of the image. Then you can obtain the image as a blob with
var image = UrlFetchApp.fetch(row[3]).getBlob()
and send it via
MailApp.sendEmail(emailAddress, subject, message, {attachments: [image]});
The full script is as follows:
function emailImage(){
var EMAIL_SENT = "EMAIL_SENT";
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 20; // Number of rows to process
var data = sheet.getRange(startRow, 1, numRows, 20).getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[0]; // First column
var subject = row[1]; // Second column
var message = row[2]; // Third column
var image = UrlFetchApp.fetch(row[3]).getBlob(); // Fourth column
var emailSent = row[4]; // Fifth column
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
MailApp.sendEmail(emailAddress, subject, message, {attachments: [image]});
sheet.getRange(startRow + i, 5).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
Images on Google Drive
If the images are stored in Google Drive, they can be accessed by file Id (the long alphanumerical part of their URL). Put the Ids in column D and replace the line with var image =
by
var image = DriveApp.getFileById(row[3]).getBlob();
Best Answer
Yes, it's possible by using a Google Sheets add-ons and Google Apps Script (GAS). Please checkout the help article Use add-ons & Apps Script to learn the basics.
If you decide to use GAS, you will need a time-driven trigger to send your email weekly.
Below is a related question that may help you to write your own script:
Trying to send email from Google Sheets with image attachment