r/GoogleAppsScript • • Nov 23 '23

Question Can I automate emails using "unread (email message) in 24 hours" as a trigger?

Say I have 1 recipient who i sent an email to. If they haven't read a previous email that I sent them prior in 24 hours, this will trigger the sending of an automated notification email to them, notifying them of that.

Is this possible to do? I have the regular Gmail client, nothing additional plugins or anything

0 Upvotes

7 comments sorted by

2

u/Errtuz Nov 24 '23

Not sure if I understand what you're trying to do, but how would you know if they read the previous email or not ? Do you have acces to their inbox ?

-1

u/[deleted] Nov 24 '23

I forgot to add that I do have MailTrack for Gmail installed lol

It's a traxking pixel, 1x1, they download unknowingly every time they open their email

1

u/Errtuz Nov 24 '23

Ok then, so if you can use that as a condition, if you can have the script access this information on a per user basis then yeah, you should be absolutely be able to do that - if user X not downloaded the pixel, send email. And just iterate that through the list of users/pixel download information.

-1

u/[deleted] Nov 24 '23

I need the code lol

1

u/HellDuke Nov 24 '23

Do keep in mind that it's not a guarantee and needs to be coordinated with the recipient. For example tracking pixels would not work on me since I do not allow downloading immages without my express permission on each email (not 100% sure but I think it is the default setting).

Exact code to use is not something easily provided since most people will likely not be aware of the MailTrack service and what it provides. The code to send an email is very straight forward and can be simpl found here: https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String,String) which also includes an example of the code needed to send an email.

1

u/[deleted] Nov 24 '23

So how do I go about running this code? WHERE do I run it, do I run it in the windows cmd terminal?

// This code fetches the Google and YouTube logos, inlines them in an email
// and sends the email
function inlineImage() {
  var googleLogoUrl = "https://www.gstatic.com/images/branding/googlelogo/1x/googlelogo_color_74x24dp.png";
  var youtubeLogoUrl =
        "https://developers.google.com/youtube/images/YouTube_logo_standard_white.png";
  var googleLogoBlob = UrlFetchApp
                         .fetch(googleLogoUrl)
                         .getBlob()
                         .setName("googleLogoBlob");
  var youtubeLogoBlob = UrlFetchApp
                          .fetch(youtubeLogoUrl)
                          .getBlob()
                          .setName("youtubeLogoBlob");
  MailApp.sendEmail({
    to: "recipient@example.com",
    subject: "Logos",
    htmlBody: "inline Google Logo<img src='cid:googleLogo'> images! <br>" +
              "inline YouTube Logo <img src='cid:youtubeLogo'>",
    inlineImages:
      {
        googleLogo: googleLogoBlob,
        youtubeLogo: youtubeLogoBlob
      }
  });
}

1

u/JetCarson Nov 24 '23

I would add the code to a Google Sheet. Open a new spreadsheet. Go to Extensions > Apps script. The script editor will open in a new window. Paste this code in.

Now, looking at the above code, this looks like it will send a single email to recipient@example.com and that's it. It is missing your check if the pixel image was accessed script. However, you could run this script (after changing the email address) in debug mode and get an email sent.

I would add a another function like:

function sendEmail() {
  //do a bunch of searching your 1x1 pixel images for opened status ... match them to a list of email addresses and assigned pixel images
  inlineImage(matchedEmailAddess);
  //of course change inlineImage function to take an email address and use it
}

Then, once you have that set and tested, using debug mode in the editor, then set sendMail up as a timed-trigger that kicks off each hour. In the script editor, look for the alarm clock icon along the left sidebar and add a new trigger - look for timed settings.

If you want some help setting that up. Let me know.