Using EWS to update calendar name in Outlook.com doesn't register online - exchangewebservices

I'm using Exchange Web Services to update a calendar name by setting the DisplayName property and then calling .Update().
It works in the sense that the call completes, and retrieving the calendar through EWS later, the DisplayName has changed, but Outlook.com doesn't register it and just shows the old name.
So basically it works but Outlook.com ignores it. I'm following the code sample here: https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/dd633615(v%3dexchg.80)
Folder folder = Folder.Bind(service, folderId);
folder.DisplayName = "Updated folder name";
folder.Update();

Related

How to create a standalone Draft message from my gmail add-on, when user is already in composer?

Use case :
I'm developing a Gmail add-on.
My add-on has a composer trigger button, which will include attachments taken from my website.
When any error occurs there, I would like to provide a Report Issue button, which will create a draft mail to my email address, with user activeUserKey value (Session.getTemporaryActiveUserKey()).
Issue :
I can use the below function to create a Draft mail.
GmailApp.createDraft(recipient, subject, body, options)
But, it requires access token. So, I tried using the below function
GmailApp.setCurrentMessageAccessToken(accessToken);
My problem here is, how can I get this accessToken from event object from composer?
event.messageMetadata.accessToken is accessible when any email is opened. But, I have only composer opened while triggering my callback function, so my event object don't have any messageMetadata.
Is there any other alternative option to create Draft mail without using accessToken / any other way to get accessToken from composer window ?
As the composer window is already open and from where you opened your add-on, the following should work. This should be inside a function that is called by the setOnClickAction, from the button. The only thing I haven't tried is to change/add a recipient. Let me know if it works.
Then your function just need to return an updateDraftBodyAction.
var updateDraftActionResponse = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftBodyAction(CardService.newUpdateDraftBodyAction()
.addUpdateContent("Google",
CardService.ContentType.MUTABLE_HTML)
.setUpdateType(CardService.UpdateDraftBodyType.IN_PLACE_INSERT))
.build();
return updateDraftActionResponse;
You can check the google code example here https://developers.google.com/gmail/add-ons/how-tos/extending-compose-ui

Is it possible via the Google Drive API to email a link to a spreadsheet that is editable without logging in to a Google Account?

I would like to be able to send an email to someone via the Drive API containing a link that will allow them to edit a spreadsheet on Google Docs without requiring them to sign in with or register for a Google account.
My first attempt (in Scala, using the Java client):
def share1(driveService: Drive, file: File, emailOfPersonToShareWith : String, emailMessage: String) = {
val writerPermission = new Permission()
.setType("user")
.setRole("writer")
.setValue(emailOfPersonToShareWith)
val insert = driveService.permissions().insert(file.getId, writerPermission)
insert.setSendNotificationEmails(true)
insert.setEmailMessage(emailMessage)
insert.execute()
}
This sends a notification email, but the link that gets sent allows the recipient to view the spreadsheet without logging in, but does not allow them to edit it without logging in.
It appears to be possible to get a link with the desired behaviour by making the document editable to anyone with the link:
def share2(driveService: Drive, file: File, emailOfPersonToShareWith : String, emailMessage: String) = {
val editableByAnyone = new Permission()
.setType("anyone")
.setRole("writer")
.setWithLink(true)
val insert = driveService.permissions().insert(file.getId, editableByAnyone)
insert.execute()
file.getAlternateLink //this link now has the desired behaviour
}
But I am unable to send a notification email in this case as that option is only available when sharing with users or groups. If, after making the document editable to anyone with the link, I then call my original share1 method to set the 'writer' permission for 'emailOfPersonToShareWith', the link that gets emailed is still not editable without logging in. The emailed link contains an "invite" URL parameter which seems to triggers this behaviour.
Is there any way to send someone a notification email via the SDK that contains a link that is editable without logging in without making the document editable to anyone with the link? Failing that, is there any way to send this email via the SDK if I do mark the document as editable to anyone with the link?

How to provide access to a UIApp for limited number of people?

I want my UiApp (GAS) application accessible only by people I explicitely invite.
I don't want to publish my application for public access, but prefer to provide some people a link (desktop shortcut) to an html file on a shared disk (so I only need to update the link to my application if I update it).
While trying to achieve that, I experience several problems.
Problem-1
I don't want the user being able to see my code.
How can I achieve that?
Problem-2
If I execute the application as me I can't retrieve the actual user (Session.getActiveUser() and Session.getEffectiveUser() both return 'me') and because of that I don't know what emails nor calendar to display.
How can I retrieve info that allows to display emails and calendar of the actual user (so NOT 'me') ?
Even if this requires an extra parameter while starting the application, it's acceptable to me.
Problem-3
I noticed that if the project uses a library, the application won't run unless the user explicitely defines the library himself. To me it seems the user should have nothing to do with that. How can avoid this problem (apart from not using libraries)?
In my case, I use a library for logging some info. This library is not located on a shared disk. Even if I disable the library (so logs will go to the system default logger) the application fails to run as a message appears stating the library is missing (and reffered in 'Resources').
What can I do to avoid this problem?
This question is rather long to answer but I'll try to make it short :
You don't need to share the code, keep it private.
The webapp should be deployed as "the user executing the app" so that all calendars, docs etc will be those of the user. You should allow anybody to access the app and create a login identification in your app itself : when the user tries to run the app you get his email (getActiveUser()) and compare this email with a list stored in scriptProperties. If the mail is not in the list then return a message saying this user is not allowed to run the app and let the script send you an alert so you know who has tried.
The Library should not be an issue, I have script using libraries that work for other users without them having to do anything except authorize.
To illustrate, here is a piece of code I use to control access of a webapp :
function doGet() {
var clientOK = false;
var client = PropertiesService.getScriptProperties().getProperty('clients').split();
var email = Session.getActiveUser().getEmail();
var app = UiApp.createApplication().setTitle('Order form').setStyleAttribute('background', 'beige');
var mainPanel = app.createAbsolutePanel().setStyleAttribute('padding','25');
var reject = app.createHTML("Hello,<BR><BR>You are connected with the address <B>"+email+"</B> that is not allowed to access this form,<BR><BR>"+
"Please contact the webMaster if you think this is an error.<BR><BR>Thank you.").setStyleAttribute('padding','25');
if(clients.join().match(email) == email){ clientOK = true ; var nom = email };
if(!clientOK){
app.add(reject)
MailApp.sendEmail('myEmail#gmail.com', 'attempt to log in form', email+' tried to access the form and has been rejected. Think about asking him what happened !')
return app
}
// continue normal code...
EDIT about problem 3 : if the Library you use writes to a spreadsheet (as a logger destination), this spreadsheet has to be shared with these users as well. Even if they don't need to open that spreadsheet from their drive, they will be able to do it as it will appear in their 'shared with me' view in their drive. That said, maybe you can get rid of that as soon as the development phase is over ?

Suppressing Email Notifications when setSharing in GAS

So, I have the following code snippet, it is part of a larger script that copies a folder of templates and customizes them for the individual user's location and data. Problem with this script is: Whenever I add an owner or editor for each of the folders and sheets, it sends an email notification for each, even though the person running the script had to authorize the script to run. This results in about 11 notification emails being sent to the user's email. I don't like spam.
Is there a way to suppress the email notifications for each shared item and changed permission, and just send one summary email that the files and folders have been copied and configured? I intend to include a link to the top level folder (destConfiguration) in the email. My original summary intent is shown below the snippet in the commented out section.
Trust me, I have searched this one as thoroughly as I can imagine, but I start getting crossover into GMail Scripts and such.
var destConfiguration = sourceConfiguration.makeCopy(targetFolder).setName(clinicId+ " Caseload Management Configuration").setOwner(userId).removeEditor(editor);
/*snip*/
//Display a confirmation message
/*var mailTo = userId;
var mailSubject = clinicID+" Caseload Mangement Tools";
var mailCC = ccEmail;
var mailBody = "Your settings and folders for your clinic's Caseload Management Tools have been configured and copied to your Google Drive.");
MailApp.sendEmail(mailTo, mailSubject, mailBody, {name: "Mgmt Tools Bot"});*/
It's not possible. Today all sharing modifications will send an email to the owner of the file.

google script Session.getActiveUser().getEmail() not working

I've developed a web app with google script and code this in my gs.
var email = Session.getActiveUser().getEmail();
Logger.log(email);
// then do something to render the Email address on the page
After publishing the script, I log in with another account and execute the script.
Then the page display this:
This application was created by another user, not by Google.
This application has access to the following personal information: email address.
But still nothing in Log and the page display nothing.
I just don't get it...
Although it's not stated explicitly in the reference documentation for Session.GetActiveUser(), my testing confirmed that your web app needs to execute as the user accessing the web app to have access to getActiveUser(). I used the code below and the logging library described here.
Depending on the use case of your application, perhaps you could create a library containing a centralized ScriptDB instance to capture the active user email. Then, create another project that works with your private spreadsheet and the same scriptDB library.
var LOG_FILENAME = 'your-log-doc'
var LOG_PATH = 'folder/subfolder/third-folder'
function doGet() {
//Change variable above to a good path and filename for you
var x = LogLibrary.InitializeLogging(LOG_PATH, LOG_FILENAME)
Logger.log(x)
var email = Session.getActiveUser().getEmail();
Logger.log("Start email logging")
Logger.log(email);
LogLibrary.fnSaveLog() //Write the save and flush the logger content
// then do something to render the Email address on the page
var HTMLToOutput = '<html><h1>A header</h1><p>' + email + '</p></html>';
return HtmlService.createHtmlOutput(HTMLToOutput);
}
I've made some tests because I am looking for a solution about the same problem,and I conclude that :
so that function can works, the web app should be executed as "user accessing the web app", and for that, the web app should be configured so that can be executed as user accessing the web app
Note that : the user will be asked to authorise the script to access, edit and
manage it's drive also receiving and sending mails (which is not evident !! for all most of users of corse").
In the end that it depend of what you will use it for.
And in google documentation nothing is mentioned about this issue!!
For a simple function that returns the email address as a text to use as script or in google html forms.. etc :
function onOpen(){
var emailName = Session.getActiveUser().getEmail();
var optionsHtml = emailName.toString().split(",");
return optionsHtml;
}
Look in the gas issues forum (google). It hax been addressed many times. Basically you need to set it as run as user accessing the app if u expect users from outside your domain. Changing that setting will qlikely break your app depending on the permissions it needs
If your app is from before the 25th of June 2013, and you are using getEffectiveUser() or getUser() methods you will need to re-authorize the script because of the new authorization experience.
You can see the documentation here.
https://developers.google.com/apps-script/scripts_google_accounts#understandingPermissions
And do not forget to execute the script before deploying.
If you want to access the user's email, make sure you have added the "https://www.googleapis.com/auth/userinfo.email" email access policy in the appsscript .json
You can see the documentation here.
https://developers.google.com/apps-script/reference/base/session#authorization