Outlook Add-In that extracts internet headers - javascript

I'm trying to create an outlook add-in that extracts and then displays essential information along with the SPF, DKIM and DMARC. At the minute everything works perfectly except for the SPF, DKIM and DMARC.
Office.onReady((info) => {
if (info.host === Office.HostType.Outlook) {
document.getElementById("sideload-msg").style.display = "none";
document.getElementById("app-body").style.display = "flex";
document.getElementById("run").onclick = run;
}
});
export async function run() {
// Get a reference to the current message
const item = Office.context.mailbox.item;
//Finds SPF, DMARC and DKIM
var headers = item.getAllInternetHeadersAsync;
var spf = getHeaderValue(headers,'spf');
var dmarc = getHeaderValue(headers,'dmarc');
var dkim = getHeaderValue(headers,'dkim');
// Write message property value to the task pane
document.getElementById("item-subject").innerHTML = "<b>Subject:</b> <br/>" + item.subject;
document.getElementById("item-sender").innerHTML = "<b>Sender:</b> <br/>" + item.sender.emailAddress;
document.getElementById("item-date").innerHTML = "<b>Received:</b> <br/>" + item.dateTimeCreated;
document.getElementById("item-to").innerHTML = "<b>To:</b> <br/>" + JSON.stringify(item.to);
document.getElementById("item-spf").innerHTML = "<b>SPF:</b> <br/>" + spf;
document.getElementById("item-dmarc").innerHTML = "<b>DMARC:</b> <br/>" + dmarc;
document.getElementById("item-dkim").innerHTML = "<b>DKIM:</b> <br/>" + dkim;
}````
This is what I have so far and I feel like it has to do with the item.getAllInternetHeadersAsync as when I was testing it, nothing was being out. So Im just wondering if theres another way to extract header information or not.
Thanks
Ive tried most of the item. tags but none worked. All I need is to extract the SPF, DKIM and DMARC.

Related

How to Retrieve multiple data using specific field in Firebase Database

I am trying to follow the firebase tutorial to retrieve data and display in Google assistant.But I am not able to retrieve multiple data from database in Dialogflow fulfillment.I want to ask user to enter register id with that field, remaining fields of student details were fetched.
I tried firebase documentation. My database connection was successful,But I am not able to retrieve data and also I want to ask user to enter the student Id i.e Register number. Suppose if i enter 191611238 [RegId] It will retrieve FirstName,EmailId and year fields.
* This is my Dialogflow fulfillment code *
const functions = require('firebase-functions');
const { WebhookClient} = require('dialogflow-fulfillment');
// initialise DB connection
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: 'ws://******.firebaseio.com/'
});
process.env.DEBUG = 'dialogflow:debug';
exports.dialogflowFirebaseFulfillment =
functions.https.onRequest((request, response) => {
const agent = new WebhookClient({
request,
response
});
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function getRegId(agent) {
const RegId = agent.parameters.RegId;
agent.add(`Thank you...`);
return
admin.database().ref('Table/').orderByChild('/RegId').equalTo("$RegId").once("value").then((snapshot) => {
var Email = snapshot.child("EmailId").val();
agent.add(`The student Mail is ` + Email);
var Regno = snapshot.child("RegId").val();
agent.add(`The student Register no is ` + Regno);
var name = snapshot.child("FirstName").val();
agent.add(`The student name is ` + name);
var year = snapshot.child("CourseName").val();
agent.add(`The student currently studying ` + year);
var Gradu = snapshot.child("GraduationTypeName").val();
agent.add(`The student Department is ` + Gradu);
});
}
// Run the proper function handler based on the matched Dialogflow
intent name
let intentMap = new Map();
intentMap.set('GetthedetailsofRegisternumber', getRegId);
agent.handleRequest(intentMap);
});
I want to get the details of student.but Iam getting Null i.e
The student Mail is null
The student Register no is null etc
I got error in Firebase console as
dialogflowFirebaseFulfillment
FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "RegId" at /Table to your security rules for better performance
Please provide me how to ask the user to enter RegId based on that I want to retrieve all fields.
function handleGetthedetailsofRegisternumber(agent){
const RegId = agent.parameters.RegId;
var ref = admin.database().ref().child("Table/");
var query = ref.orderByChild("RegId").equalTo(RegId.toString());
query.once("value", function(snapshot) {
snapshot.forEach(function(child) {
console.log(child.key);
// name field
console.log("FirstName: " + child.val().FirstName);
console.log("Mobile: " + child.val().MobileNumber);
console.log("Email: " + child.val().EmailId);
var name = snapshot.child("FirstName").val();
agent.add(`The student name is ` + name);
});
});

Fail to Send an email with attachment using Google Apps Script

function SendEmails() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Name List").activate();
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
var lr = ss.getLastRow();
var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Email Template").getRange(1, 1).getValue();
var quotaLeft = MailApp.getRemainingDailyQuota();
//Logger.log(quotaLeft);
if ((lr-1) > quotaLeft){
Browser.msgBox("You have " + quotaLeft + " left and you're trying to send " + (lr-1) + "emails. Emails were not sent.");
} else {
for (var i = 2;i<=lr;i++){
var currentName = ss.getRange(i, 1).getValue();
var currentAppNo = ss.getRange(i, 2).getValue();
var currentEmail = ss.getRange(i, 3).getValue();
var messageBody = templateText.replace("{First Name}",currentName).replace("{App No}",currentAppNo);
var subjectLine = "CONGRATULATION ON YOUR VAL APPROVAL " + currentName
var attachmentBody = DriveApp.getFilesByName("THE ROOM SCRIPT.pdf");
MailApp.sendEmail(currentEmail, subjectLine, messageBody)
} //close for loop
} //close else statement
}
I have a Google Spreadsheet with a list of emails. I want to build a routine that sends email automatically to those email addresses. I also want to attach a PDF to this email. The PDF file is located on my Google Drive.
This does not seem to work
Here are two things that you may want to change in your script.
getFilesByName() gets a collection of files (as a FileIterator object) with that name. If there is just one such file, you'll need to change that line to
var attachmentBody = DriveApp.getFilesByName("THE ROOM SCRIPT.pdf").next; // To get the first such file
Ref doc here.
As #ross said, the sendMail() function needs to include the attachment like so:
MailApp.sendEmail(currentEmail, subjectLine, messageBody, {
attachments: [attachmentBody.getAs(MimeType.PDF)]
});
Ref doc here.

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?

Check if user exists in Active Directory from client side JavaScript

I am creating a ASP.NET page for creating AD user objects. I am using JQuery for client side validation (to check if user name already exists).
I found some script on Google which returns user properties if user is found in active directory (I will convert this to return bool).
However, if you run this script (below) outside of Visual Studio by directly double clicking ScriptFile.js it works perfectly but when you try the same through visual studio it gives object undefined error at var objRootDSE = GetObject('LDAP://RootDSE');
Here is the JavaScript function code:
function Search(search) {
var arrSearchResult = [];
var objRootDSE = GetObject('LDAP://RootDSE');
var strDomain = objRootDSE.Get("DefaultNamingContext");
strAttrib = "samaccountname";
objConnection = new ActiveXObject("ADODB.Connection");
objConnection.Provider = "ADsDSOObject";
objConnection.Open("ADs Provider");
objCommand = new ActiveXObject("ADODB.Command");
objCommand.ActiveConnection = objConnection;
var Dom = "LDAP://" + strDomain;
var arrAttrib = strAttrib.split(",");
objCommand.CommandText = "Select '" + strAttrib + "' From '" + Dom + "' WHERE objectCategory = 'user' AND objectClass='user' AND samaccountname='" + search + "' ORDER BY samaccountname ASC";
try {
objRecordSet = objCommand.Execute();
objRecordSet.Movefirst;
while (!(objRecordSet.EoF)) {
var locarray = new Array();
for (var y = 0; y < arrAttrib.length; y++) {
locarray.push(objRecordSet.Fields(y).value);
}
arrSearchResult.push(locarray); objRecordSet.MoveNext;
}
return arrSearchResult;
}
catch (e)
{ alert(e.message); }
}
Please suggest how to make this work in visual studio or some other way to check if user exists in AD from client side.

createFile() in google Apps Script is not functioning properly

I am trying to create a file. It works fine when I run the following code segment from the debugger in apps script. However, when I run it real time from the spreadsheet, it says I do not have permission to call createfile. Everything that is logged is identical. The issue is not I do not have authority as I am the only one in the spreadsheet and am the owner. The purpose of the CSV is to move it from my google drive into data for BigQuery
function saveAsCSV(row) { //Doc to Csv
//row = 3; //when this is uncommented and ran from the debugger, it works.
try{
var fileName= Date.now()
fileName = fileName + ".csv";
var csvFile = convertRangeToCsvFile_(fileName,row);
Logger.log(csvFile); //Both times ran on the spreadsheet and from debug equals the same.
DriveApp.createFile(fileName, csvFile);
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("New and Open").getRange("J" + row.toString()).setValue("");
loadCsv(fileName);
}
catch(e){Logger.log("B" + e.message);} //No permission to create file
}
function convertRangeToCsvFile_(csvFileName, r) {
var ws = SpreadsheetApp.getActiveSpreadsheet();
try {
//var data = ws.getValues();
var csvFile = undefined;
var csv = "";
var row = r;
var datArray = Create2DArray(1,19);
datArray[0][0] = ws.getRange("A" + row.toString()).getValue().toString().toUpperCase();
datArray[0][1] = ws.getRange("B"+row.toString()).getValue().toString().toUpperCase();
datArray[0][2] = ws.getRange("C"+row.toString()).getValue().toString().toUpperCase();
datArray[0][3] = ws.getRange("D"+row.toString()).getValue().toString().toUpperCase();
datArray[0][4] = ws.getRange("E"+row.toString()).getValue().toString().toUpperCase();
datArray[0][5] = ws.getRange("F"+row.toString()).getValue().toString().toUpperCase();
datArray[0][6] = ws.getRange("G"+row.toString()).getValue().toString().toUpperCase();
datArray[0][7] = ws.getRange("H"+row.toString()).getValue().toString().toUpperCase();
datArray[0][8] = ws.getRange("I"+row.toString()).getValue().toString().toUpperCase();
datArray[0][9] = new Date(ws.getRange("K"+row.toString()).getValue().toString()).getHours();
datArray[0][10] = new Date(ws.getRange("K"+row.toString()).getValue().toString()).getMinutes();
datArray[0][11] = new Date(ws.getRange("L"+row.toString()).getValue().toString()).getHours();
datArray[0][12] = new Date(ws.getRange("L"+row.toString()).getValue().toString()).getMinutes();
datArray[0][13] = new Date(ws.getRange("M"+row.toString()).getValue().toString()).getHours();
datArray[0][14] = new Date(ws.getRange("M"+row.toString()).getValue().toString()).getMinutes();
datArray[0][15] = new Date(ws.getRange("N"+row.toString()).getValue().toString()).getTime();
datArray[0][16] = new Date(ws.getRange("N"+row.toString()).getValue().toString()).getFullYear();
datArray[0][17] = new Date(ws.getRange("N"+row.toString()).getValue().toString()).getMonth();
datArray[0][18] = new Date(ws.getRange("N"+row.toString()).getValue().toString()).getDate();
for(var i = 0; i < 19; i++){
if(datArray[0][i] == ""){if(i > 9){datArray[0][i] = 0;} else{datArray[0][i] = "nil";} }
if(i < 18){csv += '"' + datArray[0][i] + '"' + ",";}
else{ csv += '"' + datArray[0][i] + '"'; }
}
Logger.log("A " + csv);
Logger.log(csv + "\n" + datArray[0].join(","));
csvFile = csv;
return csvFile;
}
catch(err) {
Logger.log("C" + err);
Browser.msgBox(err);
}
}
You mention in your comment on my answer that you are using onEdit to trigger the script. Since this is a Simple Trigger, your current approach will not work. When you use simple triggers to run an Apps Script, it runs in a sandbox with reduced permissions.
See: https://developers.google.com/apps-script/guides/triggers/#restrictions
The best I can recommend is create a custom menu option with a UI popup asking for the row number to export. If the code is triggered from a menu by the user, it runs with full permission to access that users account.
Depending on your use-case, a scheduled trigger might work too. It could run every 10 minutes or every Hour and export any changes to the spreadsheet. In this case the Apps Script runs as you, with permission to access your account, and the resulting CSV would be created on your drive.
Details on how to create a custom menu: https://developers.google.com/apps-script/guides/triggers/#onopen
Details on how to create a form for the user: https://developers.google.com/apps-script/guides/ui-service
Details on time driven triggers: https://developers.google.com/apps-script/guides/triggers/installable#time-driven_triggers

Categories

Resources