Back to Blog

AUTO REPLY VIA GOOGLE!

Published on 10/3/2025

If you’re receiving repeated emails like form submissions, job applications, or customer inquiries, manually replying can quickly become a chore. Luckily, with Google Apps Script, you can automate Gmail to reply on your behalf — no third-party tools required.

In this article, you’ll learn how to create an auto-reply script that sends a polished HTML email automatically and ensures it never replies twice to the same sender.


1. What You’ll Need

Before getting started, make sure you have:

  • ✅ A Gmail account
  • ✅ Access to Google Apps Script
  • ✅ The email address you want to send replies from

2. Open Google Apps Script

  1. Go to Google Apps Script.
  2. Click New Project.
  3. Delete the default myFunction() that appears.
  4. Replace it with the code in the next step.

3. Paste the Script**

Copy and paste the following script into your new project:

function autoReply() {
  var threads = GmailApp.search('from:submissions@formsubmit.co is:inbox -label:AutoReplied newer_than:1d');
  if (threads.length === 0) return;

  var label = GmailApp.getUserLabelByName("AutoReplied");
  if (!label) label = GmailApp.createLabel("AutoReplied");

  for (var i = 0; i < threads.length; i++) {
    var thread = threads[i];

    // Check if thread already labeled
    var labels = thread.getLabels();
    var alreadyLabeled = labels.some(function(l) { return l.getName() === label.getName(); });
    if (alreadyLabeled) continue;

    var messages = thread.getMessages();
    var lastMsg = messages[messages.length - 1];

    // Placeholder name
    var userName = "User";

    // HTML Email Template
    var htmlBody = `
    <!doctype html>
    <html>
      <body style="margin:0;padding:0;background-color:#e9f1f7;font-family:Arial, Helvetica, sans-serif;">
        <div style="width:100%;padding:32px 0;background:linear-gradient(135deg,#3b82f6,#06b6d4);">
          <table align="center" width="100%" cellspacing="0" cellpadding="0" border="0" style="margin:0 auto;max-width:600px;border-radius:20px;background:rgba(255,255,255,0.9);backdrop-filter:blur(12px);box-shadow:0 6px 20px rgba(0,0,0,0.15);overflow:hidden;">
            <tbody>
              <tr>
                <td style="text-align:center;padding:32px;background:linear-gradient(90deg,#06b6d4,#3b82f6);">
                  <h2 style="color:#ffffff;font-size:26px;margin:0;font-weight:700;letter-spacing:1px;">EXAMPLE.COM</h2>
                  <p style="color:#f0f9ff;font-size:14px;margin:8px 0 0;">Via: example.com</p>
                </td>
              </tr>
              <tr>
                <td style="padding:24px;">
                  <h3 style="margin:0 0 12px 0;color:#0f172a;font-size:18px;">Dear ${userName},</h3>
                  <p style="margin:0;color:#1e293b;font-size:16px;line-height:1.6;">
                    Thank you for applying. <br>
                    Your submission has been received successfully, and our team will contact you shortly!
                  </p>
                  <hr style="margin:24px 0;border:none;border-top:1px solid #e2e8f0;">
                  <p style="margin:0;color:#475569;font-size:14px;">Need help? Just reply to this email.</p>
                </td>
              </tr>
              <tr>
                <td style="text-align:center;padding:16px;background:linear-gradient(90deg,#3b82f6,#06b6d4);">
                  <p style="margin:0;color:#f0f9ff;font-size:12px;">© 2025 Example.com. All rights reserved.</p>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </body>
    </html>
    `;

    // Send the reply
    lastMsg.reply("", { htmlBody: htmlBody, from: "admin@networthwars.live", noReply: true });

    // Label the thread so we don't reply again
    thread.addLabel(label);
  }
}

4. Grant Permissions

  1. Click Run → autoReply().
  2. Google will ask for authorization — approve the permissions so the script can access Gmail.

5. Automate with a Trigger

  1. Open the Triggers panel (clock icon on the left sidebar).

  2. Click Add Trigger.

  3. Choose the following settings:

    • Function: autoReply
    • Event source: Time-driven
    • Type: Every 5 or 10 minutes
  4. Save the trigger.

Your Gmail will now automatically check for new emails and send responses — no manual action needed!


6. Why This Works Well

Prevents duplicate replies by labeling threads. ✅ Sends beautiful HTML emails, not boring plain text. ✅ Fully customizable — change colors, branding, or sender.


7. Final Thoughts

With this setup, you’ll never have to manually respond to repetitive emails again.

Whether it’s internship applications, customer messages, or form submissions — Gmail will handle it automatically in the background.

This is just scratching the surface of what Google Apps Script can do. You can expand it to:

  • Send different replies based on subject lines.
  • Log submissions into Google Sheets.
  • Customize responses per sender.

Subscribe to our Blog

Get the latest posts delivered straight to your inbox.

No spam, ever. Unsubscribe at any time.