EWS script to create new contact then add it to public folder> parent folder >folder containing contact items - exchangewebservices

New to using EWS. I have a PowerShell script that automates onboarding new users via input (that all works great). I would like to add the following function to the script: Create new contact, then add it to the public folder > parent folder > folder containing contact items. So that all users can see the company contact
All the information for the contact card (see below) is predefined in the script already i just do not know how to use EWS.
Full Name
Company
Job Title
Email
Phone number (Business and Fax)
Address

You can create new contact by using the following link:
Creating contacts by using the EWS Managed API 2.0
Also, if you want to add it to public folder, You can use the MoveItem operation in EWS or the Item.Move() method in the EWS Managed API to move email messages, contacts, and other mailbox items into and out of a public folder.
Public folder access with EWS in Exchange

Related

How to share a google web app outside a domain preferably without creating a marketplace addon

I'm new to apps scripting and have created a web app which is container bound to a spreadsheet.
The app provides an html form for patients to record blood pressure readings as they take them during the day. A query string on the web app url identifies the individual patient and puts their readings on a sheet, unique to them, as they submit them. The script is deployed as a web app (Publish -> Deploy as web app) and in my development account it works well.
Now I want to share the script with a few other accounts not in my domain, so that they can use it independently with their own patients, with their own web app url, with readings going onto their own spreadsheet and for me to be able to maintain the code centrally.
Researching this I see official addons are now provided through the Gsuite Marketplace. It appears my choices for 'sharing' are these:
create an officially reviewed addon and put it in the Gsuite marketplace but creating an addon for the world is not what I want to do (atm anyway!)
create a private addon for inside one domain but I want to share it with several domains
there appears to be a system for testing the script as an add-on, without publishing it and for sharing the testing but this is mentioned in the Gsuite addon docs but not mentioned in the Editor addon docs and anyway it's for testing.
share the spreadsheet in my account but then all readings end up on my spreadsheet
share the spreadsheet and code to other accounts so they can make a copy but then I can't maintain the code centrally
Can anyone suggest the best way to share this web app script so other accounts not inside my domain can use it independently but ideally so I can maintain the code centrally? Thank you.
I see two solutions here. One is to add a small amount of "user management" code to your tool. For example, include some query parameters on your base url such as email and authorization key. Set up a user-management spreadsheet with your list of users, mapping their email to a secret randomly generated authorization key, and their data spreadsheet ID.
When the script is accessed with a valid email/authorization_key combination, it then opens the relevant sheet and does its thing.
In this scenario, you would either need to have access to all the relevant spreadsheets (if the code is executing "as you"), or you would need to figure out a standardised file layout or approach that let your script locate the right files on each users drive (if the code is executing "as the user accessing the web app").
Another solution here is to use an Apps Script Library. Using a library would allow you to keep the bulk of the code in the library, while having lightweight "wrapper" code bound to each of the other users spreadsheets. This wrapper code would simply pass doGet/doPost, and any other function requests back to your library.
For example:
function doGet(e){
return YourLibrary.doGet(e);
}
function doPost(e){
return YourLibrary.doPost(e);
}
function aCallback(a,b,c){
return YourLibrary.aCallback(a,b,c);
}
In the library scenario, each sheet and script can be private to the individual users, you would just need to walk them through the initial setup/deployment, and occasionally have them bump the library version and re-publish the web-app in their copies.

How to change email signature via google form with data from google directory

I am using a Google Apps Script to change the signature of each user with personal data which is accessed via Directory API. Therefore I have a Service account with Domain Wide Delegation, which impersonates with an admin account to get all the users and their data and then impersonates which each and every user to change the signature via GmailAPI.
However now in addition I want to provide a Google Form for each user where the user can add additional information to its signature and set it. The script will need the users information from the Directory but I was wondering if the same approach with impersonating is needed.
With The Apps Script advanced Gmail Service it is possible to set the signature but I did not find a way to access the users data in the Google Directory of the specific user which is sending the form.
If I a service account is needed for that I was wondering where to store the access credentials for that? I don't want is be accessible by every user.

Add users to Google Group using Google Apps Script

I'm trying to add a user to a Google Group using Google Apps Script.
Here's the code I've tried:
// Adds a user to a Google Group
function addUsertoGroup(userEmail) {
var userEmail = 'Name#gmail.com'
var groupId = "group-name#googlegroups.com";
var group = GroupsApp.getGroupByEmail(groupId);
// If email is already in group
try { var hasMember = group.hasUser(userEmail);}
catch(e){Logger.log(userEmail+" is already in the group"); return}
var newMember = {email: userEmail, role: "MEMBER"};
// This is the line which is throwing an error
AdminDirectory.Members.insert(newMember, groupId);
When running, I receive an error:
API call to directory.groups.get failed with error: Domain not found.
Any help would be appreciated.
Clarification:
You require a G Suite account to be able to use the AdminDirectory function (or to have the ability to add users to a group via Apps Script.
You can add gmail or any other non-same domain users based on the group setting you configure via https://groups.google.com
Solution:
I have a G Suite account via script.gs and I tested the code that you've shared - its perfect :) Except for the following that you need to enable, from a G Suite account.
Navigate to Resources > Advanced Google Services... and enable Admin Directory API
That's it. I created the group, enabled all settings, made the group accessible to everyone and it worked like a charm.
Let me know if you require any further clarification or assist as well.
Edit notes:
So, this is also what I had to follow to ensure everyone (even folks outside the domain could be added as users), as documented on Set Groups for Business sharing options. When you go to Groups for Business and navigate through the settings, you'd get to enable the following option that's critical -
Obviously, you're free to tweak all the other settings, as required.
You are trying to use the AdminDirectory service, this service will work only for G Suite Admin within a G Suite domain. So you need to have your domain and it will work if you add user from your domain to a group of your domain.
i.e. user#domain.com added to group#domain.com
Based on your sample code you try to add a gmail.com user to a public Google Groups for that you can't use the admin directory API because you are not admin of the domain that manage the public groups.
And in this case, as you did, you can only use the GroupsApp service and this service only allow you to check if user is in the ggroups or what is the role.
=> With GroupsApp service it is impossible to add a user to a public google group.
Stéphane

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

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();

GAS standalone app: Is there a way to create a document without an association with any google account?

If I have a standalone app which uses this piece of code:
function createDuplicateDocument(sourceId, name) {
var source = DocsList.getFileById(sourceId);
var newFile = source.makeCopy(name);
return DocumentApp.openById(newFile.getId());
}
And this app is open to everyone to use it, when the new document is created, where the document will be placed? Is there a way to create a document without an association with any google account?
If you deployed the app to run as you, the document will be created in your drive, if you deployed it to run as "the user executing the app" then it will be created in this user's drive.
There is no way to change that... The only thing you can do is to change ownership properties of the newly created document. This can be done with a Library developed by Romain Vialard if you are working inside a domain and have admin rights.
Otherwise you can only change sharing properties.
Yes, there is a way to create a document without any association to any Google account. But you would need to save the file to some other internet service, or the user would need to download it to their computer. To save the file to some other online service, you'd need to to able to communicate somehow, like through their SDK or REST API.