i want a script that sends a message to a particular cell number on event of an update in my spreadsheet or through a add menu button option.
i tried to find but couldn't see any option like that.
One of the simplest ways is to write a script to send it via email using your cell carriers email code.
Here's a list of codes https://20somethingfinance.com/how-to-send-text-messages-sms-via-email-for-free/ .
Under tools select script editor and basically just copy the following code in. Change up the EmailTo, Subject, and Body accordingly.
function sendText() {
var EmailTo = "your10digitNumber#CellcarrierCode";
var subject = "Whatever";
var body = "Text";
MailApp.sendEmail(EmailTo, subject, body);
}
In the script editor under Edit select current project triggers and setup however you want.
Adding a menu or setting up an onEdit even function in a document is pretty straightforward (just a few lines of code depending on the complexity of your application). Google Apps Script does not have built in functionality for SMS/Text messaging however.
If you want to accomplish this sms functionality, you will need to identify a company that offers an SMS/Text messaging API and access the API with a custom script. Twilio is a great tool (although not free) or you may find another API that fits your needs based on your region in this list of SMS APIs: http://blog.mashape.com/list-of-50-sms-apis/.
Once you have your service/API selected and set up and have the API Documentation, refer to the following Google Developers page to access the service API with Apps Script: https://developers.google.com/apps-script/guides/services/external.
If you're not well versed in using APIs, you can instead use MailApp to send e-mail or log any activity in another spreadsheet for tracking purposes. One other low-tech solution to consider is that spreadsheets have a built-in edit notification under Tools > Notification Rules.
I attempted to
try{
MailApp.sendEmail(phone+'#txt.att.net',subject,body);
}
catch(err){}
The email sent. It worked. BUT it did not send the text. HOWEVER, if I REPLIED to the email (from sent mail) to the phone plus carrier code it did go through. But only the reply.
Related
I want to use Google Form as a contact form on a website, and email the contents of the form (not just a notification) to a specified address.
I created a Google Form, embedded it on a website to use as a contact form for enquiries. Then created a Sheet to pull in the data from the Form. After that I created a Trigger for onFormSubmission which runs the following:
/**
* #OnlyCurrentDoc
*/
function onFormSubmission (e) {
var values = e.namedValues;
var htmlBody ='<ul>';
for (Key in values) {
var label = Key;
var data = values[Key];
htmlBody += '<li>' + label + ": " + data + '</li>';
Logger.log(label + ": " + data);
};
htmlBody += '</ul>';
GmailApp.sendEmail('me#gmail.com', 'Web Form Enquiry', '', {htmlBody:htmlBody})
}
Running this brings up a dialogue stating:
Authorization required.
'Send email' needs your permission to access your data on Google
Review Permissions or Cancel
['Send email' is my 'App' in G Suite]
Clicking Review Permissions opens a popup asking to choose an account to continue. Clicking on the account (the same account I'm logged in with and have created the form, etc with) brings up:
This app isn't verified. This app hasn't been verified by Google yet. Only proceed if you know and trust the developer.
Advanced or Back to safety
Clicking Advanced:
Google hasn't reviewed this app yet and can't confirm it's authentic. Unverified apps may pose a threat to your personal data.
Go to 'Send email' (unsafe)
It then states:
'Send email' wants to access your Google account
This will allow 'Send email' to Read, compose, send and permanently delete all your email from Gmail
Connect to an external service (Create a network connection to any external service (e.g. to read or write data)
Make sure that you trust Send emails
You may be sharing sensitive info with this site or app. Find out how Send emails will handle your data by reviewing its terms of service and privacy policies. You can always see or remove access in your Google Account.
Find out about the risks
Cancel or Allow
So, for testing purposes I clicked Allow. And it all worked beautifully! And I made the form responsive, and then I remembered I had to go back and review the permissions. After 4 hours I got lost down the rabbit hole, and crawled my way back up to here in confusion. So my questions are:
Do I need to implement OAuth?
Does Google need to verify the app?
If yes to 2, does this take weeks? (If yes, probably need to abandon this solution)
If I give the app 'permissive permissions' (as I did for testing) is there any security risk?
If I give the app 'permissive permissions' is Google going to review it and decide to stop it running?
The only reason I can imagine that OAuth is needed is that data is being taken from Sheets, an email is being created and the data is being passed to that. Is it because of the data being passed to a different 'service' than collected it? Or because a different service is instructing the creation of an email? (Or both?)
If OAuth is implemented does this mean that users will be asked to verify? Obviously, they will not require to be logged in to use a contact form on a website.
Is it possible to restrict the permissions eg to only compose emails, rather than have the ability to delete any or all emails in the account (manifest?)
Would it make any difference if I skipped the spreadsheet ie Form to email? (Can't see how, but asking just in case.)
This is my first time using these services, so hopefully, I've explained it ok.
Any advice gratefully received!
I want to use Google Form as a contact form on a website, and email the contents of the form (not just a notification) to a specified address.
Do I need to implement OAuth?
What you're doing is already OAuth flow. But it's managed by apps script. So, No.
Does Google need to verify the app?
Not for your use case.
If yes to 2, does this take weeks? (If yes, probably need to abandon this solution)
Maybe more
If I give the app 'permissive permissions' (as I did for testing) is there any security risk?
Anyone with access to your script(by implication, anyone with edit access to your spreadsheet) can change the script to send email from your account to any other website or Read or delete your email. So, Avoid providing edit permission to your Spreadsheet or script.
If I give the app 'permissive permissions' is Google going to review it and decide to stop it running?
Not if you're the only user.
The only reason I can imagine that OAuth is needed is that data is being taken from Sheets, an email is being created and the data is being passed to that. Is it because of the data being passed to a different 'service' than collected it? Or because a different service is instructing the creation of an email? (Or both?)
Yes.
If OAuth is implemented does this mean that users will be asked to verify? Obviously, they will not require to be logged in to use a contact form on a website.
You are the owner of the email, sheet and the form responses. Only you need to authorize the app/script to act on your behalf to do certain jobs like copy/paste.
Is it possible to restrict the permissions eg to only compose emails, rather than have the ability to delete any or all emails in the account
Yes.
You can use MailApp instead of GmailApp
OR Limit the scopes in apps script manifest file:
https://www.googleapis.com/auth/gmail.send
Would it make any difference if I skipped the spreadsheet ie Form to email? (Can't see how, but asking just in case.)
Reducing the number of hops it takes for the script flow is good for security. But doesn't make much difference in terms of oauth flow/permissions requested. You can use the formsubmission trigger in the form itself. Note however that you need to redesign the script according to the event object provided on formsubmit to the form. This is different from the event object provided to the spreadsheet onformsubmit.
I've set up the WebHooks in the backend of a WordPress site that I plan to use to send the Gravity Forms submissions in that WP site to my Google Sheet, with different form submissions being sent to different tabs of my Google Sheet.
I'd like to use Google Apps Script to get the WebHooks to post the form submissions to the tabs of my spreadsheet, unless there's a totally forever free (not free trial) add-on that's easy to use. From what I've researched I haven't found any such add-on, so I was hoping someone could help me with the GAS script as I'm on a time crunch.
Here's the Google Sheet I would like the form submissions to be inserted to:https://docs.google.com/spreadsheets/d/1I3pjRT_n6Np9ux-_blJnmZ8dxvXRg2zm-lWs3s_b4NY/edit?usp=sharing
Thank you!
Katie
What you are looking for is deploying your script as a Web App. This allows you to handle the methods doGet(e) and doPost(e) in your code. (Whatever variable is between the parentheses are your parameters).
To start you want to take your script and goto publish> Deploy As Web App. Change the access to Anyone, even anonymous. Then hit deploy.
The link provided after submission could then be used with the webhook. Going off of this link under the Hook column is the name for the parameter you will be looking for. Still following the eample your code should look something like this.
function doPost(e)
{
//gets the comment most recently posted.
var comment = e.parameters.comment_content;
var spreadsheet = SpreadsheetApp.openById(id);
var sheet1 = spreadsheet.getSheetByName("sheet1");
sheet1.appendRow(comment);
}
I'm curious to learn if the following scenario can be addressed using Google Apps Script (or perhaps another method?). Here's the scenario I'm dealing with.
Perform a specific subject line search when new messages are received. For example:
({subject:(keyword1 keyword2 keyword3) subject:(keyword1 keyword4 keyword5)})
If matched, perform the following actions:
Modify the subject line to include "#action"
Forward this newly renamed mail to another email address
Bonus points if I can somehow then label the original email, and archive said original mail (removing it from my inbox) in one fell swoop.
Help is most appreciated.
As per the Gmail API, you can only modify the labels of a Gmail message but not the subject or body.
To forward an email to another account, or to archive an email, you could use the message.forward() and moveThreadsToArchive() methods in Google Apps Script.
function archiveMessages() {
var query = 'label:archiveme';
var threads = GmailApp.search(query);
GmailApp.moveThreadsToArchive(threads);
threads.forEach(function(thread) {
thread.getMessages().forEach(function(message) {
message.forward("recipient#example.com");
});
});
}
Is it possible to process multiple selected emails by an addon?
The code from Google shows how to process only one selected email. I suppose 'e' would be some kind of array of accesstokens but I don't know how to access it.
function getContextualAddOn(e) {
var accessToken = e.messageMetadata.accessToken;
Logger.log("token:"+ accessToken);
GmailApp.setCurrentMessageAccessToken(accessToken);
var messageId = e.messageMetadata.messageId;
var card = createCard();
return [card.build()];
}
Thanks.
Your Apps Script code never runs on the client device, where the messages are selected in the Gmail UI - it runs on Google's servers. You can't access UI information from add-ons (there's no GmailApp.getSelectedThreads(), CardService.getActiveEmails(), etc.). You are only able to access the opened message / draft, and others in the same thread (or mailbox, depending on your add-on's scopes).
The event object received by your triggered callback function will only have a single access token. Until additional manifest triggers are added (currently only contextual and compose exist), this won't change.
As this is not Google, no one here can tell you if or when other triggers may or may not be added. You best bet is to request the feature.
My Sheet-bound script is sending an email using MailApp.sendEmail.
The emails are always sent 'from' my own Gmail account. This project is for a customer, and I need his email to be the 'from' on these emails.
Reading similar questions I learn that the I only have flexibility in changing the name and replyTo address, using the advanced options of MailApp.sendEmail. However, the email address is still mine and Google doesn't offer any control over that.
I'm not familiar enough with all of the Google services and options to find the best way to do this. My customer does have a Google Apps for Business, but I don't.
Can I somehow create the email-sending function as a standalone script under his account, and somehow call it from the project under my account?
Any other ideas?
Thanks!
Emails are always sent from the account of the user that executes the script. In case the email is sent by a triggered function (installable triggers are the only ones that are able to send emails since it requires explicit authorization) then the email is sent from the account of the user that created the trigger (and authorized it).
In your case, it seems that the easier solution would be to ask your customer to execute the script himself and initiate all the triggers himself too.
If that should not be possible then you could indeed use a standalone script that would work as a kind of proxy, ie it would receive a request to send a message and actually send it from the customer account while returning an acknowledgement to your script.
But that's a bit tricky... the first solution is more elegant.
Edit :
I found the idea of sending emails through an independent script funny so I gave it a quick try and it seems to do the job pretty easily... test code below (this code should be deployed as a standalone app from your customer account) :
function doGet(e) {
Logger.log('e = e'+JSON.stringify(e));
if(e.parameter.recipient==null){return ContentService.createTextOutput("error, wrong request "+JSON.stringify(e)+"\n\n"+e.parameter.recipient+"\n\n"+e.parameter.subject+"\n\n"+e.parameter.body).setMimeType(ContentService.MimeType.TEXT)};
try{
MailApp.sendEmail(e.parameter.recipient, e.parameter.subject, e.parameter.body)
}catch(err){
return ContentService.createTextOutput('error : '+err).setMimeType(ContentService.MimeType.TEXT);
}
return ContentService.createTextOutput('mail successfully sent').setMimeType(ContentService.MimeType.TEXT);
}
note : the code below goes in your spreadsheet script, the doGet above is an standalone app running from your customer account.
function sendMail(recipient,subject,body){
var sent = UrlFetchApp.fetch("https://script.google.com/macros/s/---------------S381kO1Kqv61E/exec?recipient="+recipient+"&subject="+subject+"&body="+body);
Logger.log(sent);
}
function test(){
sendMail('recipient#gmail.com','test message','hello world')
}
I was able to send messages from my gmail account while being logged as a different user. (the url above is intentionally truncated, I don't want anyone to send email from my account ;-)