The other day, I tried to add a new email address to my LINE alert list and suddenly realized something.

“Wait… how did I build this system again?”

The system was working perfectly, but I had almost forgotten how it was structured. That felt a bit dangerous for my future self, so I decided to write everything down as a personal memo.

While doing that, I noticed this could also be useful for beginners who might think, “I didn’t know this was even possible” or “Oh, so this is the kind of setup needed to make it work.”


What I Built

This system checks incoming Gmail messages and sends a LINE notification only when certain conditions are met.

  • The email subject contains specific keywords
  • The sender’s email address matches a predefined list

These conditions work as an OR rule, not AND. If either condition matches, a notification is sent.

Once the notification is sent, that email is automatically marked as read, so the same message won’t trigger LINE alerts repeatedly.


Overall Structure (Simple Overview)

The system consists of three main components.

  • Gmail (the data source)
  • Google Apps Script (GAS)
  • LINE Messaging API

The basic flow looks like this:

  1. GAS periodically checks unread emails in Gmail
  2. Each email is examined for subject and sender
  3. If conditions match, a LINE notification is sent
  4. Only the notified email is marked as read

A time-based trigger in GAS runs everything automatically, so there’s no need to press the “Run” button manually.


What Was Needed on the LINE Side

Creating a LINE Official Account

To use the LINE Messaging API, a LINE Official Account is required. Currently, Messaging API channels are created through official accounts rather than directly.

Required Information

To send messages from GAS to LINE, I needed the following:

  • A long-lived Channel Access Token
  • My own LINE User ID (a long ID starting with “U”)

This user ID is not visible inside the LINE app. It can be found in the LINE Developers console as “Your user ID.”

Also, the official account must be added as a friend in LINE, otherwise push messages will not be delivered.


Important Points on the GAS Side

Handling “Unread” Emails Correctly

Using is:unread with GmailApp.search() returns threads, not individual unread messages.

That means messages inside a thread may already be read. To avoid unexpected notifications, I made sure to:

  • Check each message with message.isUnread()
  • Mark only the notified messages as read

Without this, duplicate or unnecessary notifications can easily happen.

Trigger Setup Issues in Safari

When setting up triggers in Apps Script, Safari sometimes fails during the authorization step. If that happens, using Chrome usually works without issues.


How to Add New Sender Email Addresses

Sender-based alerts are managed using an array in the script.

To add a new email address, you simply add one line to that array. No other part of the code needs to be changed.

This makes maintenance easy, even after some time has passed.


How to Add Subject Keywords

Subject keywords are also stored in an array.

The check uses a “contains” match rather than exact matching, so it works well even when subject lines vary slightly.


About Attachments

This system sends text-only notifications to LINE.

Even if an email includes attachments:

  • The attachment itself is not sent
  • The notification still works normally

For my use case, this is perfect. I just want to notice important emails quickly.


Common Pitfalls

  • Never publish access tokens or user IDs
  • Always limit notifications to unread messages
  • Mark only notified messages as read
  • Too many senders will make LINE noisy

Final Thoughts

This article is not written as a step-by-step guide that guarantees you can build the exact same thing just by following it.

That’s because, these days, the easiest approach is to ask AI while building something that fits your own environment and goals.

In fact, this system wasn’t created by carefully following a predefined procedure. It started from a simple thought — “Wouldn’t it be nice if this were possible?” and gradually took shape through conversations with AI.

Being able to turn ideas like this into practical systems that actually fit your daily life, right when you think of them, really makes you appreciate what a good time this is to be building things.