Access is denied. Check credentials and try again - occurs occasionally - exchangewebservices

I've created Outlook Addin and I have an issue with email handling in C# by Exchange Api 2.2. Form time to time I get such error from users "Access is denied. Check credentials and try again" when trying to execute this code (use are mailbox owners and have full rights):
var selection = Adapter.Instance.OutlookApplicationRef.ActiveExplorer().Selection;
string entryId = selection[1].EntryID;
EWS.AlternateId objAltID = new EWS.AlternateId();
objAltID.Format = EWS.IdFormat.HexEntryId;
objAltID.Mailbox = "myemail#test.test";
objAltID.UniqueId = entryId;
//Convert PR_ENTRYID identifier format to an EWS identifier.
EWS.AlternateIdBase objAltIDBase = esb.ConvertId(objAltID, EWS.IdFormat.EwsId);
EWS.AlternateId objAltIDResp = (EWS.AlternateId)objAltIDBase;
string ewsId = objAltIDResp.UniqueId;
var psToLoad = new EWS.PropertySet(EWS.BasePropertySet.IdOnly, EWS.EmailMessageSchema.InternetMessageId, EWS.EmailMessageSchema.Sender,
EWS.EmailMessageSchema.ToRecipients, EWS.EmailMessageSchema.CcRecipients, EWS.ItemSchema.Body,
EWS.EmailMessageSchema.MimeContent);
var EWSEmailMessage = EWS.EmailMessage.Bind(service, ewsId, psToLoad);
I get this error on "EmailMessage.Bind" from time to time only. For 99 % of users it works. I have something about 5000 of users. We compared configuration in Exchange and everything is the same like with users where application works correctly. Maybe there is a better way to get email information using selected email in Outlook (2010).

I've come across this error and what we found was it was a faulty calendar permission on one of the permissions on the mailbox you are trying to access.
Hope this helps

Related

(Microsoft Dynamics Online) Get Account GUID inside embedded Web Resource

I'm trying to access entities (Contacts) in a HTML WebResource inside an Account formular in Microsoft Dynamics. However I cannot figure out how to get the record GUID (accountId) from the PageContext. It tells me the entityId is undefined.
I'm trying to replace this deprechated code line:
const accountId = parent.Xrm.Page.data.entity.getId();
I've been trying to use
const pageContext = window.parent.Xrm.Utility.getPageContext();
but the attributes are almost all null or undefined including the entityId. All it tells me is that I'm in an account record. See image. https://imgur.com/a/oeA1SOz
Thanks for any help
Yes is possible, you were close in your second attempt.
This will return the id:
var id = parent.Xrm.Utility.getPageContext().input.entityId.replace("{", '').replace("}", '');
From Microsoft docs:
Pass parameters to HTML web resources

Firebase web authenticate and add to database

I am stuck on this and the other posts I have read on here are not useful. So I've reached a point where i need to ask for help after many hours on not resolving what I feel should be a simple task. I program in Swift usually and really know little about html or javasript.
I am building a simple webpage to log-in to Firebase and a second linked page to upload data to a database. Both work fine. The problem is getting the uploaded data to link to the uid of the current user.
So I am logged into an existing user with it's own uid. How do I then upload the data to the current user did in the database? Should be simple but I am just not getting it :-(
Code for uploading data is as follows (note I have tried using both set and push):
// Generate a reference to a new location and add some data using push()
var postsRef = ref.child("users");
var newPostRef = postsRef.push({
// var newPostRef = postsRef.set({
name: _name,
property: _property,
email: _email,
phone: _phone,
Any help, or better still a working simple example would be useful. I have read the docs on Firebase, so please don't direct me there :-)
Many thanks in anticipation
It is a best practice to create a new database node using the UID generated by the account creation as the path after /users.
Right now, when you push data into /users, Firebase creates a uid for that particular array item that does not correspond to the UID of the user.
If you use set, you need to specify the path you will set which should include the long UI: /users/longGUIDhere
You can get the user id with something like this (from Firebase docs):
var user = firebase.auth().currentUser;
var name, email, photoUrl, uid;
if (user != null) {
name = user.displayName;
email = user.email;
photoUrl = user.photoURL;
uid = user.uid; // The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
}
And then you shouuld use uid to populate the path like below to save their info:
function writeUserData(userId, name, email, imageUrl) {
firebase.database().ref('users/' + userId).set({
username: name,
email: email,
profile_picture : imageUrl
});
}
I know you asked not to be referred to the Firebase docs, but it also looks like you are using an older version of the SDK, so that could be part the issue as well. I recommend taking a look at these two page, since that is where I pulled these verbatim examples:
https://firebase.google.com/docs/database/web/read-and-write
https://firebase.google.com/docs/auth/web/manage-users
var postsRef = ref.child("users/current user id or json key");
this will help you to update the details of current user.

Username with System.User

Today I wanted to greet the user in my app by name, but I did not manage to get it.
I found System.User, but lacking some examples I did not manage to get the info I needed. I saw no possibility to get the current user (id) to call User.GetFromId().
Can you guide me into the right direction? Have I been on the wrong path?
Okay, So first things first, getting access to a user's personal information is a privilege you have to request, so in your store app's Package.appxmanifest, you'll need to enable the User Account Information capability in the Capabilities tab.
Next, you'll want to be using the Windows.System.User class, not the System.User (System.User isn't available to Windows store apps, which you appear to be discussing given the tags you provided for your question)
Third, you'll want to request personal information like this.
IReadOnlyList<User> users = await User.FindAllAsync(UserType.LocalUser, UserAuthenticationStatus.LocallyAuthenticated);
User user = users.FirstOrDefault();
if (user != null)
{
String[] desiredProperties = new String[]
{
KnownUserProperties.FirstName,
KnownUserProperties.LastName,
KnownUserProperties.ProviderName,
KnownUserProperties.AccountName,
KnownUserProperties.GuestHost,
KnownUserProperties.PrincipalName,
KnownUserProperties.DomainName,
KnownUserProperties.SessionInitiationProtocolUri,
};
IPropertySet values = await user.GetPropertiesAsync(desiredProperties);
foreach (String property in desiredProperties)
{
string result;
result = property + ": " + values[property] + "\n";
System.Diagnostics.Debug.WriteLine(result);
}
}
When you call GetPropertiesAsync, your user will get a permission prompt from the system asking them if they want to give you access to that. If they answer 'No', you'll get an empty user object (but you'll still get a unique token you can use to distinguish that user if they use the app again).
If they answer yes, you'll be able to get access to the properties below, and various others.
See the UserInfo Sample Microsoft provided for more examples.

Get unread email and mark as read in one call using EWS Managed API

I have a standard routine to get an unread email from a mail server, mark it as read and then process it. It looks similar to this:
var view = new ItemView(1);
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
var findResults = ExchangeService.FindItems(WellKnownFolderName.Inbox, sf, view);
if (findResults.Items.Any())
{
EmailMessage emailMsg = findResults.Items.First() as EmailMessage;
emailMsg.IsRead = true;
emailMsg.Update(ConflictResolutionMode.AutoResolve);
ProcessMail(emailMsg);
}
This could be invoked from various processes, so I need to ensure atomicity of "find unread / mark as read" operation. In other words between Service.FindItems() and mail.Update() the same email could be read twice by different processes and result in duplicated processing.
Now, I don't want to get involved in discussion about storing processed email IDs or whether I should be using multiple processes accessing the same email server.
All I want to find out is if there is a EWS API method which does the two operations in one call? Ideally that would be something like this:
var mail = ExchangeService.GetFirstUnreadEmailAndMarkItAsRead()
No, there isn't. An EWS GetItems call doesn't modify the item.

How to get/read Email ID from a from response

I have created an application where I am collecting form responses from various users. I am getting responses with email id in responses spreadsheet. As I don't want to store data in spreadsheet so I am reading data trough responses. I am facing some challenges please guide.
Query 1
while using onFormSubmit(e) I am not able to read submitted form, given code is returning null:
var form = FormApp.getActiveForm();
Logger.log('usename:' + form.getId());
error " Cannot call method "getId" of null." although if I hard coded value of formid var form = FormApp.openById('<<form_id_xyz>>'); then it is working fine and I can read responses as well.
How can I get form responses for multiple users?
Query 2
getRespondentEmail(); is not working in my case. Even I use form id <<form_id_xyz>> and trying to get email id from responses which I have captured at the time of form submission form.setCollectEmail(true); I tried following code in onFormSubmit(e) function but dint get a result:
var formResponse=form.response;
Logger.log('email id of user: ' + formResponses.getRespondentEmail());
and another way:
Logger.log('email id of user: ' + form.getRespondentEmail());
and
Logger.log('email id of user: ' + e.values[1]);
nothing works for me. Kindly guide.
Query 1: Hope it's clear in my comment.
Query 2:
Sorry to say, I don't understand your second query problem completely.
However as per your requirement I am suggesting this code.
If you have created a form you should know the form id (I assume) so try this code.
var form=FormApp.openById('your form id here');
//this returns your form which you created//
var responses=form.getResponses();
/// this will give you all responses of your form as an array////
///iterate the array to get respondent email id///
for(var i = 0; i < responses.length; i++){
Logger.log(responses[i].getRespondentEmail());
}
I think it's important to note that at the present time the answer to your question is: You can get what they enter, but you cannot get their true verified Email Address. This is explained better in this question and one of the answers details some workarounds such as publishing form as a web script.
The accepted answer displays what email address the user has typed into the form. There is no authentication to this beyond it having an # symbol thus a user could type foofoo#zoomZoom.com and it would be viewed in the forms results and scripts.
What's annoying is that google IS capturing the user's true email address because if settings are set to Allow One Response Per User, then the user is limited to one submission -- regardless of what they put as their email account. I'm not sure why Google won't provide a method to view the submitter's login email address since it has been disclosed to the user that this will be disclosed.
Microsoft Forms does capture this.