I created a script which create an event in my calendar automatically and send an invitation to specified addresses. That works well when I specify address different from the email linked to my calendar.
But in my case I have 2 calendars so I would like to :
- Create the event in the calendar A
- Send an invitation by email, which creates at the same time the event (but not validated) in calendar B.
- This way I can choose in the calendar B to decline or not the event
To do that I just have to send the invitation to my mail address (mymail#gmail.com). That almost works :
- The event is shown in calendar B and I can choose to decline it.
- BUT I don't receive any email for the invitation. It seems that send the invitation from a an address to the same address doesn't work.
Do you know why ? And is there a way to force the sent ?
var event = cal.createEvent(titre, DateDebut, DateFin, {description : description, guests : "mymail#gmail.com", sendInvites: true});
event.setGuestsCanModify(true);
If the email is being sent by the calendar, the other way to force an email would be using the class MailApp which allows you to send emails. This option allows you to make a custom email and invitation, and If I'm remembering correct allows you to send invites to non-google accounts.
Related
I am trying to create a Google calendar event for the user who submits leave request on google form. When this form response is recorded in google sheets, I get the user email id and want to create a calendar event for them. Script creates event when I use my email id, but it gives null when I try to do the same for other user.
Here is the sample code:
CalendarApp.getCalendarById(email)
.createAllDayEvent(
'OOO - Out Of Office',
startDate,
endDate,
{
description: message,
sendInvites: true,
});
I received this error: Cannot read property "createAllDayEvent" of null
I googled this error, and someone suggested that subscribing to user's calendar may solve this issue. I used the following snippet to counter that:
var calendar = CalendarApp.getCalendarById(email);
if(calendar == null){
//user may not have access, auto-subscribe them.
calendar = CalendarApp.subscribeToCalendar(email,{hidden:true,selected:false});
}
But it is showing a new error stating: The calendar or calendar event does not exist, it was deleted, or the user doesn't have access to it
Any idea how we can make it work. Thank you.
You can't do this on Form Response (at least not reliably).
To create an event in another user's calendar they must have changed their calendar settings to be available to the public and the Access Permissions must be set to 'Make changes to events'. More information about this can be read on this help page
If these settings aren't set by the user, you're out of luck creating events for them. In this case you have two options:
Create an OAuth2 Application which the user authenticates to allow the creation of Calendar events on their behalf (though this still can't be done on form submit)
Create an event on your calendar and send them an invitation using their email address. You can give them edit permissions to the event so that they have control of it as if it were in their calendar, though in this case they will have to accept the event invitation.
I have an onEdit triggered appscript that grabs data from a spreadsheet, formats it and then sends it to an email address. Typically these messages would be sent 'from' the user that is triggering the script to run. However, I am experiencing strange behavior where the current user is not used to send the message - or used inconsistently.
A couple of notes:
Occasionally the message is sent by the current user, other times it is not (in those cases it comes from my account, which created the script)
Script trigger is an 'onEdit' script which monitors the sheet for a checkbox status change
Spreadsheet is in a Shared Drive
We are using Google apps for education
The recipient address is a mailing list tool. When I list a different email address as the recipient (internal, external, other) the message consistently comes from the current user as expected. I've no idea why the recipient would affect how Google sends the message.
I realize i could use the GmailApp library to send instead, but want to avoid the re-authorizations that are mentioned.
I wrote a script to format the text that input on Google Forms and send it by email. The email could be sent but the email address of the user who entered the text cannot be set in the From: header.
I already read the Google Apps Script API documentation. And, I already know when I use the Gmail Apps class to send emails, I can set only the Google Form owner's email address in the "From:" header.
var options = {from: Session.getActiveUser().getEmail()};
GmailApp.sendEmail(to_address, subject, message, options);
I want to set the email address of the user who entered the text in the From: header. However, my email address who is the owner of the form is set.
GMailApp (and MailApp) only allows you to use your own email address or an alias address linked with your account. This is to prevent people from acting like someone else by putting other people's addresses in the from field. If the script editor can freely change the From field, he could write anything he wants in the body and send it, posing as someone else.
It's very likely that you are using the on form submit installable trigger and in such case the GmailApp/MailApp services will send the email using the settings of the user who created the installable trigger.
To send an email on behalf of another user, instead you should use a more complex script. By one side you should use the Gmail Advanced Service, by the other side you should set this the domain-wide delegation for this script but this is only available for G Suite accounts and the domain-wide delegation requires G Suite Superadmin privileges.
I need send e-mail to the organizers of a event in Google Calendar, think in that situation of a video conference meeting : A person create a event and set a location for it, but one of the guests that are in another place set a location too, and we have rules for the locations that need to be sent by email to the organizer of the event and for that guest that included the new location if that's the case. The problem is, how can I know the user that edited that location?
I have another question too, how can i get the last event that has been created on a calendar?
how i can know the user that edited that location ?
You cant unless you set up push notifications doc
How can i get the last event that has been created on a calendar?
events.list has an order by parameter that lets you sort by the start time or by the updated.
I have just implement a simple function to send email automatic when a google form is submitted, with my current account.
When I sign in with other google account and submit this form. I recieve an email with my account (not account is signed). Is there any way to send with the account is signed?
Edit: I think I misunderstood your question...
2 things to know:
When a script sends an email using a triggered function ( a form submit trigger in this case) the mail will always be sent by the account of the creator of the trigger.
As explained below, to get the email address of the user submitting a form you must be part of a google-apps domain.
If you are using your form in a GAFE or business Google Apps account then you can use the getRespondentEmail() method but as mentioned in the documentation this does not work for normal Gmail accounts.