Send Email with Google Apps Script

INTRO

There are many ways to send an email through App Inventor. Here is another method that uses a standalone google apps script to handle just sending a message, send a text file from data in your app, or sending an image on your device. The script also allows you to check your emailing quota for the day. A normal consumer gmail account allows for the sending of 100 emails a day (24 hours), this is therefore not suitable for spamming or bulk emails above that quota level. This is a simple demonstration, you can edit your app blocks and script code to handle many other email sending options.

Setup

You will need


Script Code

A doGet(e) AND a doPost(e) function are required in the script. the doPost() is needed to send the base64 String (usually too big for a doGet()).

function doGet(e) {

  var output = '';

  if (e.parameter.FN == "textFile") {

    var blob = Utilities.newBlob(e.parameter.content, e.parameter.mimetype, e.parameter.filename);

    MailApp.sendEmail(e.parameter.email, 'Text Attachment example', 'One file is attached.', {

        name: 'Email One Attachment',

        attachments: [blob]

        });

    output = 'Email with text attachment sent';

  }

  else if (e.parameter.FN == "message") {

    MailApp.sendEmail(e.parameter.email, 'Message example',e.parameter.content, {

        name: 'Message'        

        });

        output = 'Email with message sent';

  }  

  else if (e.parameter.FN = "quota") {

    var emailQuotaRemaining = MailApp.getRemainingDailyQuota();

    output = 'Remaining email quota: ' + emailQuotaRemaining;

    

  }


  return ContentService.createTextOutput(output);

}


function doPost(e) {

  if (e.parameter.FN == "image") {

    var data = Utilities.base64Decode(e.parameter.content);

    var blob = Utilities.newBlob(data, e.parameter.mimetype, e.parameter.filename);

    MailApp.sendEmail(e.parameter.email, 'Image Attachment example', 'One image file is attached.', {

        name: 'Image',

        attachments: [blob]

        });

        output = 'Email with image attachment sent';

  }

  return ContentService.createTextOutput(output);

}

Blocks

AIA and FILES

RESOURCES