google sheets email notification when cell changes - email

I would like an email sent when a cell value is above a certain amount
I would like an email sent when cell c6 value is >=4.Heres the script I'm currently using that does not send me an email
function sheetTracker(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var cell = ss.getActiveCell().getA1Notation();
if(Session.getActiveUser()!='trdforlife#gmail.com' &&
Number(ss.getActiveCell().getValue())>=4 && cell=='c6'){
MailApp.sendEmail('yourmail#gmail.com', 'Modification in the spreadsheet',
'Cell ' + cell + ' has been modified by '+ Session.getActiveUser() +
' - new value = ' + ss.getActiveCell().getValue().toString());
}
}`your text`

Related

send email reminders based on date of expiry and a status in another column

A bit new at this I hope someone can help me :)
I have a list of properties in Col 24 and a "room status" in Col 35 and a contract expiry date in Col 37.
I need to send email reminder to myself 30 days before expiry to send email to the person and 27 days before expiry a reminder email to myself to follow up if I have response. I have this script ready but need it to trigger only if the status is "NO RENEW" in Col 35.
Below is the script I have:
function emailAlert(){
// 27 days from now
var twoWeeksFromToday = new Date();
twoWeeksFromToday.setDate(twoWeeksFromToday.getDate() + 27);
var twoWeeksMonth = twoWeeksFromToday.getMonth() + 1;
var twoWeeksDay = twoWeeksFromToday.getDate();
var twoWeeksYear = twoWeeksFromToday.getFullYear();
// 1 month from now
var newToday = new Date()
var oneMonthFromToday = new Date(newToday.setMonth(newToday.getMonth()+1));
var oneMonthMonth = oneMonthFromToday.getMonth() + 1;
var oneMonthDay = oneMonthFromToday.getDate();
var oneMonthYear = oneMonthFromToday.getFullYear();
// getting data from spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("dash");
var startRow = 3; // First row of data to process
var numRows = 4; // Number of rows to process
var dataRange = sheet.getRange(startRow, 24, numRows, 41);
var data = dataRange.getValues();
//looping through all of the rows
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var expireDateFormat = Utilities.formatDate(
new Date(row[13]),
'ET',
'dd/MM/yyyy'
);
//expiration date information
var expireDateMonth = new Date(row[13]).getMonth() + 1;
var expireDateDay = new Date(row[13]).getDate();
var expireDateYear = new Date(row[13]).getFullYear();
//checking for expiry date 27 days from now
Logger.log('2 weeks month, expire month' + twoWeeksMonth + expireDateMonth);
if (
expireDateMonth === twoWeeksMonth &&
expireDateDay === twoWeeksDay &&
expireDateYear === twoWeeksYear
) {
var subject =
row[11] + // Status
'\n' +
' - ' +
'\n' +
row[0] + // Address
'\n' +
' - ' +
'\n' +
'Did we get a response ? ';
MailApp.sendEmail('hello#gmail.com', subject, message);
Logger.log('2 weeks from now');
}
//checking for expiry date 1 month from now
if (
expireDateMonth === oneMonthMonth &&
expireDateDay === oneMonthDay &&
expireDateYear === oneMonthYear
) {
var subject =
row[11] + // Status
'\n' +
' - ' +
'\n' +
row[0] + // Address
'\n' +
' - ' +
'\n' +
'CONTRACT ENDING ';
MailApp.sendEmail('hello#gmail.com', subject, message);
Logger.log('1 month from now');
}
}
}

Automated emails from a Google Sheet

I was looking for a solution to send automated emails from a Google Sheet connected to a Google Form, so I found Google Scripts. I never worked with it (or other scripts) before, so it's all new to me. I did find a lot of information on the internet, but I still have some questions.
Let's explain the situation. So I'm selling two different products in a Google Form, they both have a different price, so I was looking for a solution to send mails to the customers with the total price and some extra information. I have a Google Sheet where all the answers are put in automatically.
So I have 12 columns, as you can see in a copy of my sheet. https://docs.google.com/spreadsheets/d/1CrA9cNAwsUdLyaxzFiJrtXxu-0eiIMiA3IEaEaIYlZo/edit?usp=sharing
The script I use is added as a picture.
The problems:
The script should prevent Google from sending duplicates, but that doesn't work
I used a formula to fill the total amount in the sheet (column L) but I can't add it in the text of the script to send it in the mail
What I want:
Automated mails, can I add the script as a add-on or how do I automate it in the sheet? Now I need to press the "play script" button every time
I want the duplicate tracker to work, so no-one gets 2 mails
I want the script to scan enough rows, so everyone gets a mail
I want the total amount in the text of the mail
That's it I guess, thanks for helping!
// This constant is written in column C for rows for which an email
// has been sent successfully.
let EMAIL_SENT = 'EMAIL_SENT';
/**
* Sends non-duplicate emails with data from the current spreadsheet.
*/
function sendNonDuplicateEmails() {
try{
// Get the active sheet in spreadsheet
const sheet = SpreadsheetApp.getActiveSheet();
let startRow = 3; // First row of data to process
let numRows = 3; // Number of rows to process
// Fetch the range of cells A2:B3
const dataRange = sheet.getRange(startRow, 1, numRows, 300);
// Fetch values for each row in the Range.
const data = dataRange.getValues();
for (let i = 0; i < data.length; ++i) {
const row = data[i];
const emailAddress = row[1]; // Second column
const message = 'Beste ' + row[4] + '\n\nBedankt voor uw bestelling, we hebben deze succesvol ontvangen!' + '\n\nU bestelde ' + row[2] + ' pakjes droge worsten en ' + row[3] + ' pakjes pannenkoeken.' + '\nDit vormt dus ' + row[2] + ' x €6 en ' + row[3] + ' x €6,5.' + '\nIn totaal komt dit op ' + ' euro.' + '\n\nDe bestelling is pas officieel na overschrijving van bovenstaand bedrag op het rekeningnummer BE04 7755 8091 4631 met als mededeling: ' + row[2] + ' DW en ' + row[3] + ' PK.' + '\n\nBij vragen of opmerkingen kunt u ons altijd een mailtje sturen via info#chirozedelgemdorp.be.' + '\n\nChiro Zedelgem Dorp dankt u, laat het u smaken!';
const emailSent = row[11]; // Elfde kolom
if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
let subject = 'Worst- en pannenkoekenverkoop | Chiro Zedelgem Dorp';
// Send emails to emailAddresses which are presents in First column
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 11).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
catch(err){
Logger.log(err)
}
}

Google Script: "EMAIL_SENT" value not set in desired column despite email being sent successfully using MailApp.sendEmail

I was wondering if you could please help. I am trying to use the MailApp.sendEmail method to send emails when a date is entered into column M. I currently use a button on the spreadsheet to trigger the sending of emails and this works fine: emails are sent.
I naturally wish for duplicate emails not to be sent and as such I wish for the "EMAIL_SENT" value to entered into Column N at the moment I trigger the sending of emails, but this does not work. This is despite my code pretty much replicating what is shown on google's own page (https://developers.google.com/apps-script/articles/sending_emails) et al.
I also wish it to generate a timestamp into Column O when emails are sent. Again, this does not work, but I can believe my approach is not correct. I'll be honest and say I am new to this!
Please advise me on where the errors are in my code.
var EMAIL_SENT = "EMAIL_SENT";
function SEWEmailReminder() {
var sheet = SpreadsheetApp.getActiveSheet();
var numRows = sheet.getLastRow(); // nothing to change
var startRow = "9"; // put the row number where the formula should start
var range = sheet.getRange(startRow, 1, numRows, 22) // Fetch the range of cells A9:Vx
var data = range.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var programmeid = row[0]; // 1st column A
var programmename = row[1]; // 2nd column B
var author = row[2]; // 3rd column C
var authoremail = row[3]; // 4th column D
var comments = row[4]; // 5th column E
var programmestatus = row[5]; // 6th column F
var datadate = row[6]; // 7th column G
var plannedcompletiondate = row[7]; // 8th column H
var completiondate = row[8]; // 9th column I
var presubjointreviewdate = row[9]; // 10th column J
var plannedsubdate = row[10]; // 11th column K
var jvissuedate = row[11]; // 12th column L
var sewresponsedate = row[12]; // 13th column M
var emailsent = row[13]; // 14th column N
var emailtimestamp = row[14]; // 15th column O
var sewreviewdate = row[15]; // 16th column P
var jvreceiveddate = row[16]; // 17th column Q
var difference = row[17]; // 18th column R
var rejectedaccepted = row[18]; // 19th column S
var recipients = row[19]; // 20th column T
var forclientacceptance = row[20]; // 21st column U
var jvreceiveddate = row[21]; // 22nd column V
var subject = "SEW Notification Email";
var message = "Dear " + author + ",\nYou have received this email to notify you that the SEW Response Date is " + sewresponsedate + " for Programme ID " + programmeid + ", titled " + programmename + ".\nKind Regards,\nAdmin"
if (row[12] != "") {
if (emailsent != EMAIL_SENT) { // Prevents sending duplicates
MailApp.sendEmail(authoremail, subject, message);
sheet.getRange(startRow + i, 14).setValue(EMAIL_SENT);
sheet.getRange(startRow + i, 15).setValue(new Date()); // set date & time stamp
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
}

Issue with vbscript emailing, unable to generate text body

So I'm trying to send an e-mail with VBscripting and otherwise it works fine, but nothing I try to write to the txt or html body, appear on the message. Here is the function I'm using:
Function EMail( myFrom, myTo, mySubject, myTextBody, myHTMLBody, myAttachment, mySMTPServer, mySMTPPort )
' This function sends an e-mail message using CDOSYS
'
' Arguments:
' myFrom = Sender's e-mail address ("John Doe <jdoe#mydomain.org>" or "jdoe#mydomain.org")
' myTo = Receiver's e-mail address ("John Doe <jdoe#mydomain.org>" or "jdoe#mydomain.org")
' mySubject = Message subject (optional)
' myTextBody = Actual message (text only, optional)
' myHTMLBody = Actual message (HTML, optional)
' myAttachment = Attachment as fully qualified file name, either string or array of strings (optional)
' mySMTPServer = SMTP server (IP address or host name)
' mySMTPPort = SMTP server port (optional, default 25)
'
' Returns:
' status message
'
' Standard housekeeping
Dim i, objEmail
' Use custom error handling
On Error Resume Next
' Create an e-mail message object
Set objEmail = CreateObject( "CDO.Message" )
' Fill in the field values
With objEmail
.From = myFrom
.To = myTo
' Other options you might want to add:
' .Cc = ...
' .Bcc = ...
.Subject = mySubject
.TextBody = myTextBody
.HTMLBody = myHTMLBody
If IsArray( myAttachment ) Then
For i = 0 To UBound( myAttachment )
.AddAttachment Replace( myAttachment( i ), "\", "\\" ),"",""
Next
ElseIf myAttachment <> "" Then
.AddAttachment Replace( myAttachment, "\", "\\" ),"",""
End If
If mySMTPPort = "" Then
mySMTPPort = 25
End If
With .Configuration.Fields
.Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = mySMTPServer
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = mySMTPPort
.Update
End With
End With
' Return status message
If Err Then
EMail = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear
Else
objEmail.send
If Err Then
EMail = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear
Else
EMail = "ok"
End If
End If
' Release the e-mail message object
Set objEmail = Nothing
' Restore default error handling
On Error Goto 0
End Function
And here is how I'm calling it:
MsgBox Email ( "address#sender.com", _
address#receiver.com, _
"This subject appears on the email correctly", _
"But this txt body does not", _
"", _
"", _
"mail.smtp-server.com", _
25 )
Like I said, the e-mail goes through alright, attachments work, subject works but for whatever reason the body never appears in the message! What is the problem?
For text use TextBody, for HTML use HTMLBody don't set both, currently you set HTMLBody to "" which will override TextBody.
You could use a flag argument;
Function EMail( myFrom, myTo, mySubject, myBody, isHTML, myAttachment...
Then
if isHTML then
.HTMLBody = myBody
else
.TextBody = myBody
end if

Can I get outcome from a formula to be send in a confirmation mail with google forms?

I've made the following script with a google form:
function myfunction (e){
var Naam = e.values[1] //column b - works fine
var Adres = e.values[2] //column c - works fine
var Postcode = e.values[3] //column d - works fine
var Woonplaats = e.values[4] //column e - works fine
var Email = e.values[5] //column f - works fine
var Aantal = e.values[6] //column g - works fine
var Totaal = e.values[9] //column j - doesn't work
var Verzendmethode = e.values[11] //column l - doesn't work
var subject = "Bestelling kaarten Getup Standup"
var message = "Beste " + Naam + ",\n\nBedankt voor uw bestelling de "
+ Aantal + " kaarten " + Verzendmethode + " wanneer u "
+ Totaal + " EURO over maakt op rekeningnr.
nl1ABNA1234567890\n\nHartelijk dank voor uw bestelling en
wij wensen u vast een prettige avond"
MailApp.sendEmail(Email, subject, message);
}
Where the value of column j[9] is the outcome of multiplying the value of column g[6] times 5 and adding up the value of column i[8] (which is either 0 or 2,5) depending on the choice in a multiple choice question.
The value of column l[11] is a predefined text, also depending on the choice in a multiple choice question.
Within the spreadsheet everything works correct. I just want to use the values of column j and l within the confirmation mail that goes out to the visitor. Instead it now states undefined.
Any ideas would be very welcome.