I would like to setup for an automatic email to be sent to the person who has requested the task via Google Sheets - forms

Good day!
I would like to create a Script on Google Sheets that will take the name (as an ID) from the "Your Name" column and tie it to an email address so that once the "x" on the "Completed" column is added, it will automatically send an alert to the email address of the person who made the request.
Screenshot of the Information collected
(the data is filled in Spanish, my apologies)

This should get you started
function onMyEdit(e) {
const sh = e.range.getSheet();
if(sh.getName() == "Your sheet name" && e.range.rowStart > 1 && e.range.columnStart == 7 && e.value.toLowerCase() == "x") {
GmailApp.sendEmail(e.user.email,"Subject","Message");
}
}
I think it should be an installable onEdit since sending emails requires permission

Related

send email from currently logged in user when checkbox is TRUE

My question is an extension of this fantastic solution but am hoping to take it one step further. Whenever a user other than me marks the checkbox as TRUE, the sender of the email is always me, since:
Installable triggers always run under the account of the person who created them
Is it possible to capture the user currently logged in and make them the sender, and if so, what am I missing in my code to make that happen?
What I've tried
I believed I had found my answer, but no such luck. This still posts the timestamp to the sheet successfully, but the email sender still shows as me. Any help would be greatly appreciated.
Edit(s):
I noticed in the above solution if (activeUser === effectiveUser) { only "worked" if typed as if (activeUser !== effectiveUser) {. In my attempts at making it work, I made that edit and forgot to revert it.
function sendEmail(e){
var sheet = e.source.getActiveSheet();
var cell = e.range;
var activeUser = Session.getActiveUser().getEmail();
var effectiveUser = Session.getEffectiveUser().getEmail();
if (activeUser !== effectiveUser) {
Logger.log(cell.getColumn());
Logger.log(cell.isChecked());
//Check if the checkbox in column G(index 7) was checked
if(sheet.getName() == "actionItems" && cell.getColumn() == 7 && cell.isChecked()){
//get current row values from column A to column F
var values = sheet.getRange(cell.getRow(),1,1,6).getDisplayValues().flat();
Logger.log(values);
var transmittalNumber = values[0];
var email = values[5];
var query = values[1];
//create and update the email's hmtl body
var templ = HtmlService.createTemplateFromFile('html_template');
templ.query = query;
var message = templ.evaluate().getContent();
//Send email
MailApp.sendEmail({
to: email,
subject: "Oatsies Action Item: "+transmittalNumber,
htmlBody: message
});
//Add timestamp at column H(index 8)
var timeZone = "GMT-7";
var date = Utilities.formatDate(new Date(),timeZone, "yyyy-MM-dd HH:mm");
sheet.getRange(cell.getRow(),8).setValue(date);
}
}
}
From the question
Is it possible to capture the user currently logged in and make them the sender?
If you are using a free Google account (usually gmail.com account) it might be possible if you use the Gmail API and set a way for active users to authorize the access to their Gmail account to send emails. Also it might be possible if you and the user are using a Google Workspace accounts and if you are able to take advantage of company-wide delegation of authority (also might be possible if you are able to configure the user's email addresses as emails aliases of your account).
Regarding the use of Session.getActiveUser().getEmail() it will return the active user email based on a complex rules i.e. your account and active user belongs to the same Google Workspace domains.
Related
Session.getActiveUser().getEmail() results are inconsistent
Domain-wide delegation
getActiveUser() doesn't return the user?

Magento 2.0.7: Something went wrong with the subscription.

get error whe subscription Newsletter. How can fix?
Here is the problem and the solution to this bug:
When we enter an new email address (one that is not connected to an extisting subscriber), the subscriber object ($this) has no id ($this->getId(); // null) yet in Magento\Newsletter\Model\Subscriber::subscribe.
The verification email is sent out before the subscriber is saved, thus the subscriber id is missing from the verification link. The link does not do anything when you click on it because the verification method in Magento\Newsletter\Controller\Subscriber\Confirm::execute rejects the link because of the missing id.
You can easily mend the problem by calling $this->save() before calling $this->sendConfirmationRequestEmail();
try {
$this->save();
if($isConfirmNeed === true && $isOwnSubscribes === false)
{
$this->sendConfirmationRequestEmail();
} else {
$this->sendConfirmationSuccessEmail();
}
return $this->getStatus();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
I simply moved the ''save'''- call a few lines up. sendConfirmationRequestEmail and sendConfirmationSuccessEmail do not seem to alter the $thisobject, so this is a valid change that does not break anything else.
I just changed the "Disable Email Communications" to yes in Magento 2 ( Stores > Configuration > Advanced > System > Mail Sending Settings > Disable Email Communications).

PayPal Merchant SDK GetExpressCheckoutDetailsResponseDetails not returning buyer's email or phone number

I'm using the PayPal Merchant SDK for .NET (v 2.15.117) and am trying to retrieve the shipping address info, customer's email address, and phone number from the GetExpressCheckoutDetailsRequestType.GetExpressCheckoutDetailsResponseDetails call. The shipping address is populated as expected but for the life of me, I can't figure out how to get the buyer's email or phone number. At a minimum we have to have the email to communicate about the order (ie tracking emails).
I see a BuyerMarketingEmail property but it is null and I am under the impression that is an optional email the buyer can choose to provide. For phone, I see a PayerInfo.ContactPhone property but that is also null (and I'm less concerned about having that but it would be nice for customer service issues or to give to ground shippers like FedEx).
I am using the PayPal sandbox if that matters.
What am I missing?
var getExpressCheckoutDetails = new GetExpressCheckoutDetailsReq();
var getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token);
getExpressCheckoutDetails.GetExpressCheckoutDetailsRequest = getExpressCheckoutDetailsRequest;
var service = new PayPalAPIInterfaceServiceService();
paypalResponse = service.GetExpressCheckoutDetails(getExpressCheckoutDetails);
if (paypalResponse != null)
{
//Success values check for a matching PayerID to validate the token response
if (paypalResponse.Ack.ToString().Trim().ToUpper().Equals("SUCCESS") &&
PayerID == paypalResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID)
{
checkout.ShippingInfo.ShippingName = paypalResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Name;
checkout.ShippingInfo.ShippingAddress1 = paypalResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
checkout.ShippingInfo.ShippingAddress2 = paypalResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
checkout.ShippingInfo.ShippingCity = paypalResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
checkout.ShippingInfo.ShippingState = paypalResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
checkout.ShippingInfo.ShippingZip = paypalResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
checkout.ShippingInfo.ShippingCountry = paypalResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
//these next two are always null
checkout.BillingInfo.Email = paypalResponse.GetExpressCheckoutDetailsResponseDetails.BuyerMarketingEmail;
checkout.ShippingInfo.PhoneNumber = paypalResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone;
}
}
Thought I'd post an answer to wrap this up -
As stated above in my comment to the original question, the email address of the buyer is PayerInfo.Payer.
Also, suddenly/magically, PayerInfo.ContactPhone began returning the phone number instead of null. I can only chalk that up to something in the Sandbox environment or my sandbox user account.

Google Form - One form submission sends two (unique) emails

Please excuse my possibly "lame" question here. I have searched everywhere and have not been able to find a solution.
Google forms -
I have one form that collects two email addresses.
I need to have each email entered into the form receive a "unique" response when the form is submitted.
Below is an example of the code I've been "trying" to make work. (Where I only get the latter email to send)
I thank you in advance for your time.
Oliver
// this would be the first email sent to e.values[3] - the first email on the form
function formSubmitReply(e) {
var userEmail = e.values[3];
MailApp.sendEmail(
userEmail,
"Help Desk Ticket1",
"Thanks for submitting your issue. \n\nWe'll start " +
"working on it as soon as possible. \n\nHelp Desk",
{name:"Help Desk"}
);
}
// this would be the second email sent to e.values[4] - the second email on the form
function formSubmitReply(e) {
var userEmail = e.values[4];
MailApp.sendEmail(
userEmail,
"Help Desk Ticket - FYI form is sent",
"The form a has been submitted. \n\nWe need to start " +
"working on it as soon as possible. \n\nThe Reger Group",
{name:"The Reger Group"}
);
}
This is a blind shot (haven't tested), but here is my guess: you are creating the same function twice, thus the second replaces the first one. Functions are unique, if you can only have one function as callback of the form submission, you should adapt it to do everything you need within the one function call.
Here's what you could do:
// Sends distinct messages for each recipient
function formSubmitReply(e) {
// First mail recipient and message
MailApp.sendEmail(
e.values[3],
"Help Desk Ticket1",
"Thanks for submitting your issue. \n\nWe'll start " +
"working on it as soon as possible. \n\nHelp Desk",
{name:"Help Desk"}
);
// Second mail recipient and message
MailApp.sendEmail(
e.values[4],
"Help Desk Ticket - FYI form is sent",
"The form a has been submitted. \n\nWe need to start " +
"working on it as soon as possible. \n\nThe Reger Group",
{name:"The Reger Group"}
);
}

Exclude specific email address from form submissions

I am totally new to PHP and I am just trying to block spam in my forms. I have
figured out how to do a honeypot (url field) with the following code that
blocks 90% of the spam - but this one irritating emailer gets through
(let's call them redacted#example.com). I would like to write one line of
code in my form that just says if the email field is filled out with the text
'redacted#example.com', then don't pass the form through. Is there anyone who can help me do this?
// if the url field is empty
// if(isset($_POST['url']) && $_POST['url'] == ''){
// then send the form to your email
// mail( 'myemail#me.com', 'Contact Form', print_r($_POST,true) );
// }
// otherwise, let the spammer think that they got their message through
Use this code
if(isset($_POST['url']) && $_POST['url'] == '') {
if ($_POST['email'] != 'dukang2004#yahoo.com') {
// then send the form to your email
mail( 'myemail#me.com', 'Contact Form', print_r($_POST,true) );
}
}