Read email headers in Outlook Web Access (OWA) - javascript

I am developing a outlook Web App (Office 365 Developer). Regarding that, is there a way to read the headers of the selected mail which lays on inbox?. I am using Exchange server 2013. I would like to use Jquery or Javascript for write the code.
I tried to add "Message Header Analyzer" from Microsoft ( link:- 'https://store.office.com/message-header-analyzer-WA104005406.aspx?assetid=WA104005406'). Now it is working properly and it can read headers. But I need to implement the same functionality using my own codes.
If anyone can provide a good reference as a start, I would greatly appreciated that. (because, I got a great effort in searching google. But.. still no luck)
thanks in advance.

First of all, I would like to thank all the persons who responded to me to develop a solution to this. Special thanks should go to #FreeAsInBeer and MrPiao. After spending several days I was able to develop the following solution for getting mail headers. I removed all the unnecessary business logic from the code and finally came up with the following code. It can be used for reading the headers of inbox emails using JQuery.
I am making an EWS request outside to get the headers. From its callback method, I can retrieve the expected result. Afterwards, it is better to use jQuery.parseXML to read and manipulate the response (which is not included in the code)
I hope this explanation will help you.
var _mailbox;
var _ItemId1
(function () {
"use strict";
// The Office initialize function must be run each time a new page is loaded
Office.initialize = function (reason) {
$(document).ready(function () {
app.initialize();
_mailbox = Office.context.mailbox;
_ItemId1 = _mailbox.item.itemId;
});
};
})();
function getSelectedEmailHeaders() {
// Wrap an Exchange Web Services request in a SOAP envelope.
var var1 = '<?xml version="1.0" encoding="utf-8"?>';
var var2 = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
var var3 = ' <soap:Header>';
var var4 = ' <t:RequestServerVersion Version="Exchange2010" />';
var var5 = ' </soap:Header>';
var var6 = ' <soap:Body>';
var var7 = ' <m:GetItem>';
var var8 = ' <m:ItemShape>';
var var9 = ' <t:BaseShape>IdOnly</t:BaseShape>';
var var10 = ' <t:AdditionalProperties>';
var var11 = ' <t:FieldURI FieldURI="item:Subject" />';
var var12 = ' <t:FieldURI FieldURI="item:MimeContent" />';
var var13 = ' </t:AdditionalProperties>';
var var14 = ' </m:ItemShape>';
var var15 = ' <m:ItemIds>';
var var16 = ' <t:ItemId Id="' + _ItemId1 + '" />';
var var17 = ' </m:ItemIds>';
var var18 = ' </m:GetItem>';
var var19 = ' </soap:Body>';
var var20 = '</soap:Envelope>';
var envelopeForHeaders = var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8 + var9 + var10 + var11 + var12 + var13 + var14 + var15 + var16 + var17 + var18 + var19 + var20;
//Calling EWS
_mailbox.makeEwsRequestAsync(envelopeForHeaders, callbackForHeaders);
}
//This Function called when the EWS request is complete.
function callbackForHeaders(asyncResult) {
//Write the content of the asyncResult on console
console.log(asyncResult);
}
Thank You. Kushan Randima

Related

How do I use javascript code in a web request C#

I'm not fully sure how to explain this: but I need to execute javascript code on a site via a C# webrequest, and use a GET request on the site with the js code executed.
I need to put the code
function getTitlesAndLinks() {
var arr = [...document.getElementsByTagName('h3')];
var filteredHeadings = [];
var filteredLinks = [];
arr.forEach(x => filteredHeadings.push(x.innerText));
arr.forEach(x => filteredLinks.push(x.baseURI));
var printToScreen = "";
for(let i = 0; i < filteredHeadings.length; i++) {
printToScreen +=
"<div><p>" +
filteredHeadings[i] +
"</p><p><a href=" +
filteredLinks[i] +
">" +
filteredHeadings[i] +
"</p></a></div><br>"
}
return printToScreen;
}
document.body.innerHTML = getTitlesAndLinks();
Into google's search and get the results
Any idea on how I can do this?
For more insight, I am using the Leaf.xNet library for my HTTP requests
I have tried to do this by adding java headers and stuff but I have no idea where to start

Google App Script: Authentication failing on UrlFetchApp.Fetch()

My code:
var username = "";
var password = "";
var options = {};
options.headers = {
"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)
};
var html = UrlFetchApp.fetch("https://www.4for4.com/fantasy-football/full-impact/cheatsheet/Flex/38351/ff_nflstats/adp_blend", options).getContentText();
Logger.log(html);
I read through a few posts like this one but still having trouble getting the data I need. The result is HTML from the redirected login page. Is it possible this site uses a different Authorization type or do I need to pass something else in the header?

Dynamics Crm Invoking Workflow from external source

Scenario:
I would like to invoke an already defined workflow or a custom action from a web page which is located outside the CRM Dynamics context. (Let's say MS CRM 2011-2013-2015-2016 and 365)
My solution:
My idea would be about defining a kind of controller page into the CRM context accessible from the web and execute the rest call within that page (through javascript).
This page will be able to read input parameters and execute the right rest call.
Does it make sense? Could you suggest a better implementation?
Thanks in advance!
If you have the resources, you can setup a service utilizing the following methods and then ajax it.
private static void ExecuteWorkflow(Guid workflowId, Guid entityId)
{
try
{
string url = ConfigurationManager.ConnectionStrings["crm"].ConnectionString;
ClientCredentials cc = new ClientCredentials();
cc.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
OrganizationServiceProxy _service = new OrganizationServiceProxy(new Uri(url), null, cc, null);
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
{
WorkflowId = workflowId,
EntityId = entityId
};
ExecuteWorkflowResponse r = (ExecuteWorkflowResponse)_service.Execute(request);
_service.Dispose();
}
catch (Exception ex)
{
//Handle Exception
}
}
If you're unable to have the service on the same domain as the CRM server, you should be able to impersonate.
cc.Windows.ClientCredential.Domain = "DOMAIN";
cc.Windows.ClientCredential.Password = "PASSWORD";
cc.Windows.ClientCredential.UserName = "USERNAME";
You can find more details here.
https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.executeworkflowrequest.aspx
You can invoke a workflow in a js like this:
You can query the workflowId by its name and the type definition.
var entityId = // The GUID of the entity
var workflowId = // The GUID of the workflow
var url = // Your organization root
var orgServicePath = "/XRMServices/2011/Organization.svc/web";
url = url + orgServicePath;
var request;
request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<s:Body>" +
"<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"<request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">" +
"<a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">" +
"<a:KeyValuePairOfstringanyType>" +
"<c:key>EntityId</c:key>" +
"<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + entityId + "</c:value>" +
"</a:KeyValuePairOfstringanyType>" +
"<a:KeyValuePairOfstringanyType>" +
"<c:key>WorkflowId</c:key>" +
"<c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">" + workflowId + "</c:value>" +
"</a:KeyValuePairOfstringanyType>" +
"</a:Parameters>" +
"<a:RequestId i:nil=\"true\" />" +
"<a:RequestName>ExecuteWorkflow</a:RequestName>" +
"</request>" +
"</Execute>" +
"</s:Body>" +
"</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", url, false);
// Responses will return XML. It isn't possible to return JSON.
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.send(request);
If the request.status is 200 the request was succesfull. This was tested on an CRM2011 enviroment.
I recommend you to create a WCF rest or web api, reference the IOrganizationService and from that use the operation of the CRM service. It is better to call a intermediate WCF than the IOrganizationService directly.

Google script doGet TypeError: Impossible to call method "getSheetByName" of null

I have a spreadsheet bound google apps script and I would like to use the doGet function to control the spreadsheet/mail sending from the outside. Basically a user gets a mail onFormSubmit with two links (I'm trying with the dev version of my code):
https://script.google.com/a/macros/..mydomain.../s/...myID.../dev?line=6&answer=ok
https://script.google.com/a/macros/..mydomain.../s/...myID.../dev?line=6&answer=no
The function is the following:
function doGet(e){
var sp = PropertiesService.getScriptProperties();
var ssId = sp.getProperty('thisSpreadsheet');
var sheetName = sp.getProperty('richiestaFerieSheetName');
Logger.log(ssId + ' ' + sheetName)
var ss = SpreadsheetApp.openById(ssId);
Logger.log(ss + ' ' + ss.getName());
var foglioRichiestaFerie = ss.getSheetByName(sheetName);
foglioRichiestaFerie.setActiveRange((foglioRichiestaFerie.getRange(e.parameter.line, 1)));
handleRequest(e.parameter.answer=='ok' ? true : false, false);
}
But I get the TypeError mentioned in the title.
The log correctly shows ssId, sheetName, ss and ss.getName(), so I can't understand why the getSheetByName method is not working properly.
Any hint?
Thanks for your attention!
Could you try the code like below and see what happens ?
first run init then use the url with parameters as you did.
function init(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
PropertiesService.getScriptProperties().setProperty('richiestaFerieSheetName',ss.getSheets()[0].getName());
PropertiesService.getScriptProperties().setProperty('thisSpreadsheet',ss.getId());
}
function doGet(e){
var sp = PropertiesService.getScriptProperties();
var ssId = sp.getProperty('thisSpreadsheet');
var sheetName = sp.getProperty('richiestaFerieSheetName');
Logger.log(ssId + ' ' + sheetName)
var ss = SpreadsheetApp.openById(ssId);
Logger.log(ss + ' ' + ss.getName());
var foglioRichiestaFerie = ss.getSheetByName(sheetName);
foglioRichiestaFerie.setActiveRange((foglioRichiestaFerie.getRange(e.parameter.line, 1))).setValue('succes');
var answer = handleRequest(e.parameter.answer=='ok' ? true : false, false);
return ContentService.createTextOutput(answer).setMimeType(ContentService.MimeType.TEXT);
}
function handleRequest(result){
Logger.log('result = '+result);
return 'result is '+result;
}
Using this url (my test webapp) :
https://script.google.com/a/macros/insas.be/s/AKfycbxsbr6uBB1B22uYUipmSG-blLVrJ0JB_hmFBy3kLGt7ZQlI8pw/exec?line=6&answer=ok
you should get this result in your browser :
and this one in the first sheet

retry sql connection using JavaScript

I know using javascript is not the best way to connect to a SQL server but this is for an in-house application. I connect using the following:
dbNSConnection = new ActiveXObject("ADODB.Connection") ;
var sNSConnectionString="Driver={SQL Server};TrustedConnection=Yes;Server=" + sNSServer + ";Database=" + sNSDatabase + ";UID=" + sNSUID + ";PWD=" + sNSPWD;
dbNSConnection.Open(sNSConnectionString);
How can I make sure connection has gone thru and how do I retry if not connected?
Isn't there any other way you could get this done on the codebehind, and pass the results to the javascript? This may be an example of what I'm talking about originally.
If not, can't you simply do the following?
try
{
dbNSConnection = new ActiveXObject("ADODB.Connection") ;
var sNSConnectionString="Driver={SQL Server};TrustedConnection=Yes;Server=" + sNSServer + ";Database=" + sNSDatabase + ";UID=" + sNSUID + ";PWD=" + sNSPWD;
dbNSConnection.Open(sNSConnectionString);
//Run rest of query here
}
catch(err)
{
var message = err.message;
//Finish building errors message here
}

Categories

Resources