Undefined e.values on google email notifications - email

I am using script editor in google spreadsheets to send an auto response email. However, I received Summary of failures notifications suggesting an invalid email: undefined (on the Mail.App line). I don't know how this error came about. Please help. Thanks so much.
function myFunction(e) {
var Nickname = e.values [2];
var email = e.values [10];
var subject = "Form Submitted"
var message =
"Thank you, " = + Nickname + ". Your response is accepted. You may want to check our website # iydsphilippines.weebly.com for registration payment details. Thanks and we hope to see you soon!";
MailApp.sendEmail(email, subject, message);
}
Here is a link to a copy of my spreadsheet.

<>
I'm no expert however I also had the same issue and by trial and error I have discovered what the problem is.
It seems that recently Google have "upgraded / changed" the way fields are evaluated.
If any fields are blank then problems arise and as your email field in column K (i.e. the 10th field counting the first as zero) and some of the others are blank it seems to get confused. Until Google fix this "undocumented feature" I have a workaround.
Move your Email column to nearer the beginning i.e. straight after the name for example but before any optional fields, then renumber it in the code and you should be OK.
Specifically in your example: Move Column K to be Column C and renumber "var email = e.values [10]" to be "var email = e.values [2]" That should do it.
Good Luck and let me know how you get on. From Lester in the UK

Related

New line works for Gmail but not Outlook

Here's the code I'm using to send an email. It works perfectly when the email goes to Gmail (it sends four short tables with a line break between each one). However, when it goes to Outlook the second table (1,16) doesn't have new lines between the table entries while the other three tables still do (I don't know if it's related to those values specifically since the tables are identical in format). I understand there's probably some difference between email services, but is there a simple way to have the emails be consistent with new lines when arriving in both places? Thank you.
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet4=ss.getSheetByName('Copy');
var emailAddress = sheet4.getRange(2,12).getValue();
var subject = sheet4.getRange(2,13).getValue();
var message = sheet4.getRange(1,15,sheet4.getRange(31,15).getValues(),1).getValues().join('\n')+
sheet4.getRange(1,14,3,1).getValues().join('\n')+
sheet4.getRange(1,16,sheet4.getRange(31,16).getValues(),1).getValues().join('\n')+
sheet4.getRange(1,14,3,1).getValues().join('\n')+
sheet4.getRange(1,17,sheet4.getRange(31,17).getValues(),1).getValues().join('\n')+
sheet4.getRange(1,14,3,1).getValues().join('\n')+
sheet4.getRange(1,18,sheet4.getRange(31,18).getValues(),1).getValues().join('\n');
MailApp.sendEmail(emailAddress, subject, message);
}

Emails generated by Googleappscript are skipping my inbox

I have a shared google sheet that when someone enters their info it prompts the next individual with an email that's automatically generated by the script. These emails prompt a dozen individuals and show up as coming from my email. This has functioned perfectly for months.
In the past week or so I've stopped emails have stopped coming to my inbox. The still shows up in "Sent" and also under "All Mail" but I'm not sure if that's just the "sent" message". All other users receive emails normally. Also, if I change my target address to a different email it works fine. Basically, it appears i can't send myself an email.
I have recently started using email filters which I know is the most likely culprit in these situations. None of them currently use the "Skip Inbox" function.
I have no idea why these emails don't show up for me despite working for everyone else as well as if I enter an alternate email address.
Edit #1:
Below is the section of code that emails the next person. As stated it appears to be working perfectly because everyone else except myself gets an email. Also if I change my email to an alternate email that works as well. It appears the issue is solely when the script emails myself from the same email address.
Also, I noted that I was previously receiving emails. This may have been untrue. As a testing measure I previously "CC'd" myself with every email that went out so that I could track that the system was working well. You'll note in the code that my email address is stored in the variable "emailAddress2" and that the CC line has now been commented out. I may not have been receiving the actual email sent to myself before but actually only receiving the CC'd version.
Here's the code:
function emailNext (JustPickedName, NextToPickName, SelectedDate) {
// Function Sends emails to the next Person in the list
Logger.log("Into Email Next");
//Set all the Email characteristics
SelectedDate = Utilities.formatDate(new Date(SelectedDate), "GMT", "EEE, MMM d, yyyy"); //Format the Date for inclusion in the email
var StaffMember = StaffList.find(StaffList => StaffList.Name === NextToPickName);//Find Emails address by finding name in Emails Object
var subject = ' You have a pick pending in the ' + ActiveWeekSheetName + ' sheet';
var message =
'<p>Dear Dr. ' + NextToPickName + '</p>' +
'<p>You have a pick pending on ' + SelectedDate + '. Please look at the ' + ActiveWeekSheetName + ' sheet.</p> <p> Dr. ' + JustPickedName + ' has just made a pick and you are up.</p>' +
'<p>You can make your selection here: GGH Room Selection</p>';
MailApp.sendEmail({
to: StaffMember.Email,
//bcc: emailAddress2,
name: 'PickListBot',
subject: subject,
htmlBody: message})
Logger.log("StaffMember.Email: " + StaffMember.Email);
}
What you are describing might in fact be a bug.
Since this is the case, I suggest you check this issue here on Google's Issue Tracker and star it in order to get any updates with regards to it.

Send a personnalised email from a Google Form

I'm starting a new project. I have to send a confirmation email when someone purchases a book with my Google Form. By now, I can send an email when you complete the form but I can't put the name of the buyer and the number of books in the email. F.ex : Hello "John", you gonna receive your "3" books in a week.
I've tried something like this :
function sendEmail(e) {
var formreponse = e.responses;
var itemreponse = formreponse.getItemResponses();
var number= itemreponse[5].getResponse(); //because it's in the 5th columns of the spread sheets
var name= itemreponse[3].getResponse();
And then I just write a simple code like this
var TextToSend = "blablabla" + name + " blabla" + number + ".";
GmailApp.sendEmail(emailTo, subject, TextToSend, options);
But I've got an error message:
Cannot read property 'responses' of undefined.
And I don't know why!
It's very frustrating for me not to be able to finish this simple task.
Issues:
When running this function manually, through the editor, no event object is passed, and so e is undefined. You should not run this function manually.
responses is not a valid Event property of Form submit triggers.
Solution:
Install an onFormSubmit trigger, either manually or programmatically, so that the function will run automatically when the Form is submitted, and e will be populated.
Change e.responses to e.response:
var formreponse = e.response;
Reference:
Event Objects > Google Forms events > Form submit

titanium multiple recipients email dialog

im using titanium and need to send an email to multiple recipients. the official docs only show how to send to one individual email address.
can someone please give a more concrete example how the getToRecipients and setToRecipients methods are applied correctly so that an email is sent to multiple recipients?
https://developer.appcelerator.com/question/149943/emaildialog-gettorecipients-does-not-work
i need to pass an array (contacts) to the emailDialog.ToRecipients property:
["email#example.net","email2#example.net"]
the code below does not work with this error message (ive also tried it unsuccessfully without the "[]" in setToRecipients):
Basic functions[2807:70b]
["email#example.net","email2#example.net"]is not a valid email
address.
var emails = JSON.stringify(contacts);
var emailDialog = Ti.UI.createEmailDialog();
emailDialog.setToRecipients([emails]);
emailDialog.subject = "Hello from Titanium";
emailDialog.messageBody = '<b>Appcelerator Titanium Rocks!</b>';
emailDialog.open();
thx for any info on this!
Have you tried this?
emailDialog.setToRecipients(contacts);
The Appcelerator Documentation says that EmailDialog.toRecipients is an String [].
See u!
Why do you pass your contacts through JSON.stringify and then put it inside array with one element?
EmailDialog.setToRecipients method requires array of strings, and every single one string should be proper email address. To make it work change your code into:
var emailDialog = Ti.UI.createEmailDialog();
emailDialog.setToRecipients(contacts);
emailDialog.subject = "Hello from Titanium";
emailDialog.messageBody = "<b>Appcelerator Titanium Rocks!</b>";
emailDialog.open();
I'm assuming that contacts variable contains this array (based on your error message):
var contacts = ["email#example.net","email2#example.net"];

Copy specific text from email message to spreadsheet

I get my checking account balance emailed to me once per day. I want to use Google Apps Script to pull the balance from the email message and plug it into my checking account spreadsheet. I am a novice to coding, but so far I have figured out how to do the following, which gets me a log of HTML code of the correct email message:
function myFunction() {
var thread = GmailApp.getUserLabelByName("CHK BAL").getThreads(0,1)[0]; // get first thread in inbox
var message = thread.getMessages()[0]; // get first message
Logger.log(message.getBody()); // log contents of the body
}
However, because this method returns the HTML code for the email message and not the actual message text, it doesn't contain the balance number that shows up in the email itself.
I tried substituting getPlainBody in place of getBody, but it returns a null value in the Log.
The question posted here is pretty much my same question (Google script that find text in my gmail and adds it to a spreadsheet?), but even with Mogsdad's reply and helpful links I haven't been able to figure out what's going wrong.
Can anyone help redirect me on how to get the email content instead of the null value?
(Once that's solved, I can't say that the link on Mogsdad's other reply is very clear about how to identify the currency and copy it into the spreadsheet, but of course I haven't been able to play around yet since I can't even access the content yet.)
Thanks!
EDIT 1
See Serge's answer below for instructions on how to parse the HTML. I used those functions to grab the text of the most recent Bank Account Balance email from a Gmail label/filter and drop it into a cell in my spreadsheet.
Then I was able to use the following equation in an adjacent cell to strip it down to just the currency number:
LEFT(RIGHT(A5,LEN(A5)-FIND("$",A5)),FIND(CHAR(10),RIGHT(A5,LEN(A5)-FIND("$",A5)))-1)+0
Of course, this works for me because the currency number is always preceded by $ (the first, and in my case, only $ to appear in the text) and always followed by CHAR(10). Anyone trying to apply this formula would need similar consistency before and after the value they are seeking to isolate.
You could try this code snippet originally written by Corey G on SO to get the text from the html content. I use it quite often and it works nicely most of the time :) (Thanks Corey)
function getTextFromHtml(html) {
return getTextFromNode(Xml.parse(html, true).getElement());
}
function getTextFromNode(x) {
switch(x.toString()) {
case 'XmlText': return x.toXmlString();
case 'XmlElement': return x.getNodes().map(getTextFromNode).join('');
default: return '';
}
}
And a test function to try it :
function test(){
var html = GmailApp.getInboxThreads()[0].getMessages()[0].getBody();
throw(getTextFromHtml(html));
}
As to why getPlainBody() is returning null, it is most likely due to a bug in Google Apps Script. The issue has been filed at https://code.google.com/p/google-apps-script-issues/issues/detail?id=3980.
From that thread: "It seems the messages affected contain HTML in their content. A possible workaround involves using getBody() instead of getPlainBody() and parsing through the HTML directly."