Outlook Add-In API Office365 - javascript

I'm developing an Outlook Add-In for Outlook Online O365 with Javascript code.
Through the API I retrieve the object MailItem (Office.context.mailbox.item).
Is it possible to export the MailItem to file .msg and upload it to SharePoint Document Library?

You can upload Mailitem body as Document in Library. To get the mail Item body
var item = Office.context.mailbox.item;
if (item.itemType == Office.MailboxEnums.ItemType.Message) {
itemType = item.itemType;
itemID = item.itemId;
subject = item.subject;
body = getBody(item);
}
function getBody(item) {
Office.context.mailbox.item.body.getAsync("html", { asyncContext: "callback" }, function callback(result) {
body = result.value;
});
}
The Body content will be as Byte[]. So that You can create a new document with this byte[]. Also you can get the Attachments. So You can upload that too. Let me know if this helps.

Related

Accessing HTML script variable from google script

I'm trying to put together a picker in google sheets.
Once a file has been uploaded to google drive, I want the url to be posted in the current cell in the spreadsheet.
This is my pickerCallback located in an html file:
var message;
function pickerCallback(data) {
var action = data[google.picker.Response.ACTION];
if (action == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
var id = 'https://drive.google.com/open?id=' + doc[google.picker.Document.ID];
google.script.run.accessSpreadsheet();
} message = id;
document.getElementById('result').innerHTML = message;
}
This returns the url in the picker dialog box.
My accessSpreadsheet function looks like this and is located in a google script file:
function accessSpreadsheet() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var currentCell = sheet.getCurrentCell();
currentCell.setValue(message);
return spreadsheet;
}
The function runs but it cannot define message. Is there a way to access the variable defined in the function in the html file from the google scripts function? Or is there another better way to do this?
Solution:
Pass the string id from client side to server.
Snippets:
google.script.run.accessSpreadsheet(id);
function accessSpreadsheet(id) {
currentCell.setValue(id);
Reference:
Client-Server communication

How to open outlook using javaScript on client machine?

I Have java code which open outlook in server . but i want to opent outlook on client machine and fill Body with HTML content . is it possible using javaScript , VbScript or any other Technology .
public static void main(String[] args) {
// System.setProperty("java.library.path", "/path/to/library");
Display display = Display.getCurrent();
Shell shell = new Shell(display);
OleFrame frame = new OleFrame(shell, SWT.NONE);
// This should start outlook if it is not running yet
OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl");
site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
// now get the outlook application
OleClientSite site2 = new OleClientSite(frame, SWT.NONE,
"Outlook.Application");
OleAutomation outlook = new OleAutomation(site2);
//
OleAutomation mail = invoke(outlook, "CreateItem", 0 /* Mail item */)
.getAutomation();
setProperty(mail, "To", "testTo#gmail.com"); /*
* Empty but could also be
* predefined
*/
setProperty(mail, "Bcc", "testBcc#gmail.com"); /*
* Empty but could also be
* predefined
*/
setProperty(mail, "Cc", "testCc#gmail.com"); /*
* Empty but could also be
* predefined
*/
setProperty(mail, "BodyFormat", 2 /* HTML */);
setProperty(mail, "Subject", "Top News for you");
setProperty(mail, "HtmlBody",
"<html>Hello<p>, please find some infos here.</html>");
File file = new File("d:/vicky.txt");
if (file.exists()) {
OleAutomation attachments = getProperty(mail, "Attachments");
invoke(attachments, "Add", "d:/vicky.txt");
} else {
MessageDialog
.openInformation(shell, "Info",
"Attachment File c:/temp/test.txt not found; will send email with attachment");
}
invoke(mail, "Display" /* or "Send" */);
}
HTML - Javascript: Simple mailto in html a tag, see below for the simple markup.
Click here to mail
Once clicked, it will open Outlook. (Actually it will open the default mail client)
Java:
Sample code: open Outlook and add an attachment.
new ProcessBuilder("C:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.exe","/a","C:\\Desktop\\stackoverflow.txt").start();
First Argument = path to Outlook.
Second Argument = Outlook attachment command.
Third Argument = Attachment path.

SkyDrive API Displaying a file

I'm working with Skydrive APIs, and I would like my user tobe able to open a view about a file where you can edit it (the same view as we can have about a file when you're on the skydrive web page).
There may be a WL function for it but I can't find it. An other solution would be for me to get the URL of the view page and open it in a new window with javascript.
I have implemented this solution using SkyDrive and its API. You can try this script out within Microsoft's Interactive Live SDK online tool as well. The key is to obtain SkyDrive's redirect link for the file you are looking to open. This redirect link is returned for each file in the Get api's json result.
Processing Steps:
Initializes Windows Live jscript api client
Authenticate with Windows Live (skydrive) OAuth
GetFiles: Get a list of all files within your SkyDrive account. This could be adjusted for your needs and focused to just get a list for a specific folder with your SkyDrive account
onFilesComplete: iterate through json response looking for an item with a type='file' and file name you are looking to open. In this, case a file name 'robots.txt'
display details about the found file
using the found file's "link" attribute, open url in a new window browser window. This will open the file using SkyDrive default action. For known file types such as code files, this will open them in SkyDrive's online file editor. Otherwise, the default action will be to download the found file
Example Code:
WL.init({ client_id: clientId, redirect_uri: redirectUri });
WL.login({ "scope": "wl.skydrive" }).then(
function(response) {
getFiles();
},
function(response) {
log("Could not connect, status = " + response.status);
}
);
function getFiles() {
var files_path = "/me/skydrive/files";
WL.api({ path: files_path, method: "GET" }).then(
onGetFilesComplete,
function(response) {
log("Cannot get files and folders: " +
JSON.stringify(response.error).replace(/,/g, ",\n"));
}
);
}
function onGetFilesComplete(response) {
var items = response.data;
var foundFolder = 0;
for (var i = 0; i < items.length; i++) {
if (items[i].type === "file" &&
items[i].name === "robots.txt") {
log("Found a file with the following information: " +
JSON.stringify(items[i]).replace(/,/g, ",\n"));
foundFolder = 1;
//open file in a new browser window
window.open(items[i].link);
break;
}
}
if (foundFolder == 0) {
log("Unable to find any file(s)");
}
}
function log(message) {
var child = document.createTextNode(message);
var parent = document.getElementById('JsOutputDiv') || document.body;
parent.appendChild(child);
parent.appendChild(document.createElement("br"));
}

Firefox add-on sdk : how to use simple-storage API in a content script?

I am making a Firefox add on using toolbar button by Erik Vold and I would like to know how to have access simple-storage API in a content script. I know that you cannot access the API directly.
var data = require('self').data;
var tabs = require('tabs');
var pageMod = require('page-mod');
var ss = require('sdk/simple-storage');
var tbb = require('toolbarbutton').ToolbarButton({
id: 'button',
label: 'us-button',
image: data.url('img/on.png'),
onCommand: function () {
tabs.activeTab.attach ({
contentScriptFile: [
data.url('jquery/jquery.min.js'),
data.url('jquery/jquery-ui.js'),
data.url('recuperation.js'),
data.url('dialog.js')
],
contentScriptOptions: {
imgfr: data.url('img/fr.png'),
imgen: data.url('img/en.png'),
imglogo: data.url('img/logo.png')
}
});
}
});
My question is : how to have access to simple-storage API in my content script dialog.js
tabs.activeTab.attach (...) returns a worker with which you can use to sent messages between the content script and the addon. With this you can have the content script send messages to the addon about what data to store in simple-storage.
So the addon side would look like:
let worker = tabs.activeTab.attach(...);
worker.port.on('simple-storage', function(newData) {
ss.storage = newData;
});
and the content script side would look like:
self.port.emit('simple-storage', newData)
when you have newData to save.

Use a HTML/Javascript form to create outlook email with embedded images using ActiveXObject

Afternoon All,
I need to be able to embed images into an outlook email via a html form that runs locally on a workstation desktop. There is no internet access. All machines are Windows with Outlook 2007.
The below code works great for creating emails with a HTML body, but I also need to embed images into the email that are stored on the local documents folder of the user.
Is there a way to find out what directory path is to the users documents folder?
And how can I embed the images so they show within the body content NOT as an attachment?
<script type="text/javascript">
function OpenOutlookDoc()
{
try
{
var outlookApp = new ActiveXObject("Outlook.Application");
var nameSpace = outlookApp.getNameSpace("MAPI");
mailFolder = nameSpace.getDefaultFolder(6);
mailItem = mailFolder.Items.add('IPM.Note.FormA');
mailItem.Subject="a subject test";
mailItem.To = document.getElementById("name").value;
mailItem.HTMLBody = document.getElementById("name").value + " " + "<b>bold</b>";
mailItem.display (0);
}
catch(e)
{
alert(e);
// act on any error that you get
}
}
</script>
var outlookApp = new ActiveXObject("Outlook.Application");
var nameSpace = outlookApp.getNameSpace("MAPI");
mailFolder = nameSpace.getDefaultFolder(6);
mailItem = mailFolder.Items.add('IPM.Note.FormA');
mailItem.Subject="a subject test";
mailItem.To = document.getElementById("name").value;
mailItem.Attachments.Add("C:\pictest.jpg");
mailItem.HTMLBody = "<html><p>This is a picture.</p><img src='cid:pictest.jpg' height=480 width=360>";
mailItem.display (0);

Categories