google sheets email script not runnable by all shared people - email

I have a google sheet shared with other people (I'm the owner) and in it there is a button linked to a corresponding bundle script that send me an email when the user logged press that button (so if I click the button I send an email to me).
All the other people have the "edit" privileges but when they click the button an error occurs saying that it's impossible to send the mail (when I click all works perfectly).
The accounts associated to the other people has the same email domain of mine (not gmail, but related to the same company).
It seems like that the script has different privileges because I have no problem, while the other people do.
As normal, at the first time they click to the button they (but also me) had to accept the google authorization to "send email as you" (as the avatar of the current account logged).
This is the code of the button:
'''
var sheet = SpreadsheetApp.getActiveSheet();
var sel = sheet.getSelection();
var sel_range = sel.getActiveRange();
var message = sel_range.getValues();
// get task IDs
var prev_values = sel.getNextDataRange(SpreadsheetApp.Direction.PREVIOUS).getValues();
var cod_tickets = [];
for (var k in prev_values){
cod_tickets.push(prev_values[k][0]);
}
var emailAddress = SpreadsheetApp.getActive().getSheetByName('Manager').getRange('I2').getValue();
var subject = 'ticket ' + cod_tickets;
MailApp.sendEmail(emailAddress, subject, message);
'''
I say that they send an email to me, because the "emailAddress" variables will be filled with the value of the cell that contains my email address.
Any ideas?

Have a look at the documentation for restrictions for simple triggers:
They cannot access services that require authorization. For example, a
simple trigger cannot send an email because the Gmail service
requires authorization, but a simple trigger can translate a phrase
with the Language service, which is anonymous.
Solution:
Use an installable trigger instead.
Go to Edit->Current Project's trigger
Click on +Add trigger
Select event type On edit.
Your function should no be named onEdit, because otherwise both the simple and installable trigger would fire at once which can lead to problems.
The problem:
The installable trigger will fire for every user, but it will fire on your behalf, so the email will always be you.
If this is a problem, you will need to use a service account that will impersonate the session user, which will make things more complicated.

Related

Why cant I send emails through Google Sheets using a Mobile device?

I opened up a spreadsheet and inserted a Drawing to use it as an Action Button, then I assigned the following script to it:
function sendEmail() {
var emailAddress = 'myemail#gmail.com';
var message = 'test-message';
var subject = 'test-subject';
MailApp.sendEmail({
to: emailAddress,
subject: subject,
htmlBody: message
});
}
Everytime I click the button from a PC, it works fine, I receive the test email instantly. But when I try to test it using any sort of mobile device it won't let me click the button.
Why hasn't google fixed this?
How can I effectively make my script send an email from google sheets using a mobile device? I've already tried with onEdit() and data validation instead of buttons but this doesn't work with the MailApp.sendEmail function, so it doesn't resolve my problem.
Please help
This is a known issue(Star it to show support). Apps Script works from official mobile apps, but buttons with scripts assigned to them do not.
onEdit simple trigger does not work because you need email sending permissions. For this case, an onEdit Installable Trigger can be used.

How to send email by simple email address using crm?

I'm working with Dynamics CRM 2016, I want to send an Email from crm using an email address that the user insert (the email Id is taken from a field in incident-Entity and not from crm-user) according to examples online the option is to use entityreference from another entity that will hold and get the Email address, is there a way not to use Entityreference but instead get my email address from a simple field on incident form?
You can use e-mail addresses that are not associated with e-mailaddress fields. It just requires a few steps.
In the UI navigate to Settings > System Settings > tab Email > header "Set Email form options".
Make sure setting "Allow messages with unresolved email recipients to be sent" is Yes.
Now you can use literal e-mail addresses like in this example:
var sender = new EntityCollection();
sender.Entities.Add(new Entity("activityparty")
{
["addressused"] = "me#home.test"
});
var recipients = new EntityCollection();
recipients.Entities.Add(new Entity("activityparty")
{
["addressused"] = "info#acme.test"
});
var eMail = new Entity("email")
{
["from"] = sender,
["to"] = recipients,
["subject"] = "Just a test",
["description"] = "Body of your e-mail"
};
organizationService.Create(eMail);
You can do it programmatically! You can send an email to a person who is not a Lead/Contact/Account.. The CRM will send email but it will show un resolved referenced when you open it in CRM
Update:
but instead get my email address from a simple field on incident form?
This is not possible in CRM UI. But possible using the code snippet from the blog link in comment. You have to query the textbox content and put in recipient party address.
(These two lines are for sending email to activity party email Id from associated record non-email field from CRM UI, without any code or customization for this particular scenario)
Unfortunately you cannot achieve it.
Only way is associated record.

Is it possible, in NetSuite, to workflow a button to create a new email with no set recipient

currently we have a custom record with a list/record field that links to an opportunity and i can create a button that creates new emails (via workflow) pulling recipient information from the contact on the opportunity record but what i want to know is if there is a way to replicate the "New Email" button usually found on a record's Mail Merge tab as i want to be able to press a button to open an email template that has no recipient set as currently the send email workflow option has both recipient and sender as mandatory fields - is this possible?
You can edit the Custom Record Type to check the 'Enable Mail Merge' checkbox, then you should have this functionality.
If you want the functionality to be available via a button in the main button group, I don't believe this is possible using a workflow only; however you can achieve this with scripting. To do this, create a User Event script with a Before Load function to add the button to the form, and a Client Script which can be called on clicking the button. Upload and deploy to the Custom Record Type that you want the email button to appear on. For this answer I'll assume you have at least a basic knowledge of creating a script record - let me know if you need more information.
The User Event script:
function emailButton(type, form)
{
//add a custom button on the form
//specify the function name of the Client script created in Step 2
form.addButton('custpage_Add', 'Start Email','startEmail();');
//set the internal id of the Client script created in Step 2
form.setScript('customscript_ppcs_start_email_client');
}
The Client script:
function startEmail() {
new_message([['transaction',document.forms['main_form'].elements['id'].value],['entity',document.forms['main_form'].elements['companyid'].value],['template',['66']]], 'EMAIL');
}
You can modify the template used by replacing the '66' with the internal ID of the template you want, or you can remove it. You can also remove the 'entity' as you don't want the recipient to be set. Below is an example with both removed:
function startEmail() {
new_message([['transaction',document.forms['main_form'].elements['id'].value]], 'EMAIL');
}

Alfresco: Modifying email link

I have deployed a custom workflow, and have email notifications correctly setup for each task. The email links currently look like the following:
https://myCompany.com/share/page/task-details?taskId=activiti$58788
This link takes the user to the details view of the task, and requires them to hit the "Edit" button at the bottom to actually perform the task. Ideally, I would like to change the link to the following:
https://myCompany.com/share/page/task-edit?taskId=activiti$58788
As task-edit allows them to immediately edit the form and perform the task. How might I go about making this change (for just this workflow)?
To change the email template(s) for all notifications: wf-email.html.ftl located in Data dictionary/Email templates/Workflow notification
Change the following html snippet:
${shareUrl}/page/task-details?taskId=${args.workflowId}
Into
${shareUrl}/page/task-edit?taskId=${args.workflowId}
If you're using your own notification mechanism, then create a new email template based on this one and use the path in your Mail task or JavaScript mail action.
---UPDATE---
You can use this JavaScript in you're workflow to send an email, still it's easier to use the AlfrescoMailtask.
// create mail action
var mail = actions.create("mail");
mail.parameters.to = "test#alfresco.com";
mail.parameters.subject = "You've got mail";
mail.parameters.from = "server#alfresco.com";
mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Workflow notification/My_custom_Template.ftl");
mail.parameters.text = "some text, in case template is not found";
// execute action against a document
mail.execute(document);

Change the displayname of the sender when sending mail via o365?

Is it possible to control the display name of the sender when sending mails with the office 365 OutlookServicesClient?
I.e., I want to use, say mailer#domain.com as the sender which is configured with the name some name#domain.com in office 365. But for a given mail I want the from name to instead be some other name#domain.com.
I've tried this:
Message draftMessage = new Message
{
Subject = subject,
Body = body,
ToRecipients = toRecip,
CcRecipients = ccRecip,
From = new Recipient()
{
EmailAddress = new EmailAddress() { Address = "mailer#domain.com", Name = "Some other name#domain.com" }
}
};
But the mail is still sent with the preconfigured name of some name#domain.com.
So, is what I want possible?
According to the reference documentation for the Message object, what you want to do is possible. However, logic tells me that shouldn't be possible, and furthermore, the testing I did showed me it wasn't possible (or isn't working). I will follow up on this and update this answer when I get a definitive answer, but at this time, it appears like you can't change the name of the sender (or it's broken).
UPDATE: The From property is writable. I've tested this using pure REST, so I can't speak exactly to what the client library you are using is doing, but I think the request is being transformed to prevent spoofing.
It is possible to control the display name of the sender, but you can only do so with other users in your Office 365 tenant. To do this, sign in to the Office 365 Admin Portal, go to Users, then Active Users, then select the user (User A) that you want to send on behalf of. Click Edit and select Mailbox Permissions. Add the alias or email address of the user (User B) who is running the code (the user authenticated with your app) to the first box under Send email from this mailbox. This will allow you to set the From property of a message sent by User B as User A.
I understand this isn't exactly what you were after, but having the ability to send email as any email address can lead to some bad stuff. Hope this helped!