Compare the values in the table before sending the email

After attempting to execute this particular script, I am encountering an issue where no emails are being sent to the user's email address. The functionality of the script involves comparing values in a specific column in a sheet (column 10) and sending an email with the differentiated content when the user selects options 1, 2, or 3. Please see the code snippet below:

function mutisendemail(e) {
if (e.values[10] == "1") {
    var useremail = "<a href='/cdn-cgi/l/email-protection' class='__cf_email__' data-cfemail='1561706661557278747c793b767c793b'>[email protected]</a>";
    var subject = "test1";
    var body = "number 1 ";
    var photo = DriveApp.getFilesByName('test1.jpg');
    MailApp.sendEmail({
        to: userEmail,
        subject: subject,
        body: body,
        attachments: [photo.next()]
    });
}
if (e.values[10] == "2") {
    var useremail = "<a href='/cdn-cgi/l/email-protection' class='__cf_email__' data-cfemail='6a1e0f191e2a0d070b030644090507'>[email protected]</a>";
    var subject = "test2";
    var body = "number2";
    var photo = DriveApp.getFilesByName('test1.jpg');
    MailApp.sendEmail({
        to: userEmail,
        subject: subject,
        body: body,
        attachments: [photo.next()]
    });
}
if (e.values[10] == "3") {
    var useremail = "<a href='/cdn-cgi/l/email-protection' class='__cf_email__' data-cfemail='fe8a9b8d8abe99939f9792d09d91'>[email protected]</a>";
    var subject = "test3";
    var body = "number3";
    var photo = DriveApp.getFilesByName('test1.jpg');
    MailApp.sendEmail({
        to: userEmail,
        subject: subject,
        body: body,
        attachments: [photo.next()]
    });
}
}

Answer №1

Remember, it is important to pay attention to the casing of variables in your code. For example, useremail and userEmail may be treated differently. Once corrected, you should see the email in your inbox. Here is the adjusted code:

function sendSimpleEmail(mynumber){
  var useremail = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d100418101c14113d1a101c14">[email protected]</a>";
  var subject = "test"+mynumber;
  var body = "number "+mynumber;
  var photo = DriveApp.getFilesByName('MyFile.pdf'); 

  MailApp.sendEmail({
    to: useremail,
    subject: subject,
    body: body,
    attachments: [photo.next()]
  });
}  

function sendConditionalEmail(){
  var mySheet = SpreadsheetApp.getActiveSpreadsheet();
  var myCell = 'B5';
  var cellValue = mySheet.getRange(myCell).getValue();
  if(cellValue=="1"){
    sendSimpleEmail("1");
  }
  else if(cellValue=="2"){
   sendSimpleEmail("2");
  }
  else if(cellValue=="3"){
   sendSimpleEmail("3");
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React JS - In order to display multiple children, consider utilizing an array rather than individual elements

Currently, I am employing React for my application and utilizing an API located at http://localhost:8080/api/suppliers/supplier/list to fetch data. Upon inspecting the Google Chrome console, this is the format of the data structure I am receiving: 0:{ ...

If I do not specify whether a variable is declared using var or let, what will be its scope?

As someone who is new to JavaScript, please forgive me if my question is not entirely valid. What will be the scope and type (var/let) of a variable if I do not specifically define it as var or let? For example: function f1(){ a="Sample" console.log(" ...

Validation in ASP.Net to ensure the correct number of days between the arrival and departure dates

One of my project requirements involves checking the validation of the number of days entered between two date selectors (From & To Dates). The constraint is that the difference should not exceed 100 days. I'm considering using ASP.NET validators for ...

Every time I attempt to send a request, I consistently encounter an error. The combination of React and MongoDB seems

Recently diving into the world of IT, I've been immersing myself in React and JavaScript by taking online video courses. As I was working on a website for one of these courses, I ran into various errors, particularly when trying to handle requests wit ...

Moving information from Ajax to PHP

I'm experiencing an issue with sending data from AJAX to PHP on the same site, "testpage.php". The PHP script doesn't seem to be displaying the data being sent. Using jQuery/Ajax: <script src="http://code.jquery.com/jquery-latest.js" type="t ...

Multiple buttons are linked to a function, causing the sharing of internal variables

I have a situation where I need to bind ajax calls to multiple buttons, each button being unique based on attached data attributes. The issue arises when the internal variables of the function are shared among different buttons. This leads to problems if ...

Lighting uniformity concept in Three.js

My 3D model needs to be uniformly lit from all angles without any shadows. Currently, I am using a Spotlight, but its directional nature only lights up certain parts of the model at a time. One solution I am considering is to place a spotlight at each cor ...

PHP - contact form is live for just 2 hours daily

Hello, this is my first time here and I could really use some assistance. Please bear with me as English is not my strong suit compared to most people here, but I'll do my best to explain my query. So, I have a PHP script for a contact form on my web ...

Executing Promises in an Array through JavaScript

LIVE DEMO Here is a function provided: function isGood(number) { var defer = $q.defer(); $timeout(function() { if (<some condition on number>) { defer.resolve(); } else { defer.reject(); } }, 100); return defer.pro ...

Utilize generic types within methods in TypeScript

Here is a snippet of code I'm working on in TypeScript: public static sortByProperty<T>( array: T[], prop: string ): void { var availProps: string[] = Object.getOwnPropertyNames( T ); // or something typeof T, anyway I got error i ...

Preventing typing during onKeyDown event in React/JavaScript and other languages

One of the reasons why I opt to use onKeyDown is because the language for typing is Korean. With multiple inputs on the page, my aim is to prevent users from typing more than 20 bytes. //this function calculates the byte length const getByteLength = (s,b ...

Tips for aligning an image in the middle of a column within an ExtJS GridPanel

My goal is to center the icon horizontally within the "Data" column: Currently, I have applied textAlign: center to the column: Additionally, I am using CSS in the icon renderer function to horizontally center it: Despite these efforts, the icon remains ...

What is the best way to verify and handle an undefined array in order to display an error message?

Currently working on a ternary statement to display the certification of a movie (e.g. PG, R...). If the array length is zero or undefined, I'm aiming to output an error message stating "No Certification Available For This Movie". While I have succes ...

Is there a way to identify whether the image file is present in my specific situation?

I have a collection of images laid out as shown below image1.png image2.png image3.png image4.png … … image20.png secondImg1.png secondImg2.png secondImg3.png secondImg4.png secondImg5.png ……. …….. secondImg18.png My goal is to dynamically ...

How can I create a React component that is accessible and controllable from external sources?

Attempting to create a Dialog component using React and Material-UI. Currently, the component behaves like a traditional Material-UI dialog with a button inside the class that opens the dialog. However, I aim to achieve the same behavior as the default Ma ...

Having difficulty linking the Jquery Deferred object with the Jquery 1.9.1 promise

I have been developing a framework that can add validation logic at runtime. This logic can include synchronous, asynchronous, Ajax calls, and timeouts. Below is the JavaScript code snippet: var Module = { Igniter: function (sender) { var getI ...

Generating a file with multiple lines and initiating the download using the Chrome.downloads.download function

On my client side, I am creating some content and trying to download it using chrome.downloads.download. However, when the file is downloaded, the new lines are missing. I am adding new lines in the code snippet below: lineContent += '\r\n& ...

Is it possible to simultaneously employ two asynchronous functions while handling two separate .json files?

Is it possible to work with 2 .json files simultaneously? My attempt did not succeed, so I am looking for an alternative method. If you have a suggestion or know the correct syntax to make this work, please share. And most importantly, does the second .j ...

Guide to obtaining ngPrime autocomplete text when the button is clicked within Angular 6

I am currently utilizing the ngPrime autocomplete feature to retrieve data from a service. My goal is to capture the text entered in the autocomplete field whenever a button is clicked. I attempted to access the value using getElementById.value within th ...

What is the process for updating a MySQL database by clicking a button?

Hey there, I have a bit of a dilemma. I know that accomplishing this task can't be done solely with PHP; I believe Ajax/Javascript is required. Unfortunately, my knowledge in these areas is quite limited, so I could really use your assistance. Here&a ...