How to open outlook using javaScript on client machine? - javascript

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.

Related

Sqlite: How to insert text entered by the user into a sqlite table using Node/Express

I am trying to find out how to pass client (HTML form) data to a Node/Express/sqlite back-end - not sure how to package up the request on the client side and/or extract the request on the server side.
Client code:
// listen for the form to be submitted and add a new dream when it is
dreamsForm.onsubmit = function(event) {
// stop our form submission from refreshing the page
console.log("SUBMIT clicked!!!");
event.preventDefault();
// jeng: save the value to post
var data = {dream: dreamInput.value}; // jeng: JSON
const dreamRequest = new XMLHttpRequest();
dreamRequest.open('post', '/putDreams', true);
dreamRequest.setRequestHeader('Content-Type', "application/json;charset=UTF-8"); // jeng - after open but before send
//dreamRequest.send(JSON.stringify(data));
dreamRequest.send(data);
};
Sever code:
// jeng: added insert a new row to the Dreams table
app.get("/putDreams", function (request, response) {
console.log("insertRows called!!");
var stmt = db.prepare("INSERT INTO Dreams VALUES (?)");
var val = request.body.dream;
//var s = JSON.parse("test")
//request.json();
console.log("1 "+request);
console.log("2 "+request.body);
console.log("3 "+request.body.dream);
//console.log("4 "+s);
//stmt.run("test"); // this works!! test is inserted
stmt.run(val); // this doesn't work - val is undefined - null is inserted
stmt.finalize();
response.redirect("/");
});
My specific need is to simply take a piece of text entered by the user and insert it into a sqlite table using Node/Express. I've searched everywhere to no avail so far. Any suggestions/pointers would be gratefully appreciated. Thanks in advance

Outlook Add-In API Office365

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.

How to call a backend C# function from front end Javascript function in ASP.NET

I am currently doing an unpaid internship in C# and Asp.net. My employer has asked me to write out a javascript function so as to tell the user if they are sure if they want to delete a record from the database before deleting it.
After some research I was able to write out the Javascript function to tell the user if they are sure they want to delete this record before actually deleting it from the database.
The javascript function works. However now I have the problem of how do I call the backend C# function which will actually delete the record from the database from the front end javascript function which I have just written?
Here is my code:
Javascript function:
function watchdelete()
{
if (confirm("Are you Sure You want to delete this Manufacturer?") == true)
{
__doPostBack('btnDelete_Click','');//"PageMethods.btnDelete_Click();
}
else { }
}
Front end part which calls the javascript client side code attached to the delete button:
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClientClick=" return watchdelete()" OnClick="btnDelete_Click1" />
Back End C# function which I want to invoke in order to delete the record from the database:
(Please note I will be happy as long as I call this function and it executes, you need not worry
about its internal workings too much. Thank you)
protected void btnDelete_Click(object sender, EventArgs e)
{
String com, command, findmodel;
if (txtManufactureName.Text != "") // If the manufacturer name is not null
{
if (txtManufactureName.Text == grdManufact.SelectedRow.Cells[1].Text) // And the manufacturer name must not be
{ // Changed from selected one
string strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString();
try
{
using (SqlConnection conn = new SqlConnection(strConnectionString))
{
conn.Open(); // Connect to database
String moderated = (checkBoxModerated.Checked) ? "true" : "false";
findmodel = "SELECT * From VehicleModels WHERE ManufacturerID = '" + txtManID.Text + "';";
com = "SELECT * From VehicleManufacturer WHERE ManufacturerName = '" + txtManufactureName.Text + "' AND Ismoderated ='" + moderated + "';";
command = "DELETE From VehicleManufacturer WHERE ManufacturerName = '" + txtManufactureName.Text + "' AND Ismoderated ='" + moderated + "';";
SqlDataAdapter finder = new SqlDataAdapter(findmodel, conn);
DataTable dat = new DataTable();
int nummods = finder.Fill(dat);
if (nummods == 0)
{
SqlDataAdapter adpt = new SqlDataAdapter(com, conn);
DataTable dt = new DataTable();
int number = adpt.Fill(dt); // try to find record to delete
if (number == 0) // If there is no such record to delete
{ // Indicate this to user with error message
txtMessage.Text = "Sorry, there is no such record to delete";
}
else
{ // Otherwise delete the record
using (SqlCommand sequelCommand = new SqlCommand(command, conn))
{
sequelCommand.ExecuteNonQuery();
txtMessage.Text = "Manufacturer Deleted Successfully";
txtManufactureName.Text = ""; // Reset manufacturer name
txtDescription.Text = ""; // Reset Description
checkBoxModerated.Checked = false; // clear moderated checkbox
}
}
}
else
{
txtMessage.Text = "Sorry. You must delete associated models first.";
}
conn.Close(); // Close the database connection. Disconnect.
}
BindGrid(); // Bind Manufacturer Grid again to redisplay new status.
}
catch (SystemException ex)
{
txtMessage.Text = string.Format("An error occurred: {0}", ex.Message);
}
}
else
{
txtMessage.Text = "Sorry. You cant change the manufacturer name before deleting";
}
}
else
{ // Otherwise give error message if manufacturer name missing
txtMessage.Text = "Please enter a manufacturer name to delete";
}
}
Any ideas will be appreciated.
Let's simplified your validation function to:
function confirmDelete(){
return confirm("Are you Sure You want to delete this Manufacturer?");
}
Then your button with OnClientClick attribute will be something like
OnClientClick=" return confirmDelete()"
As long as your validation function returns false .NET will not submit your code the server.
To give people an understanding of how to call backend functions from client side Javascript I would like to put the answer here in my own words -> Simple plain English:
Step
1. Write your Javascript function and place it on the client side and enable scripts whatever, not going into too much detail here. See the code snippet below for an example
<script type = "text/javascript" >
function watchdelete()
{
return confirm("Are you Sure You want to delete this Manufacturer?");
}
Write your button or control front end code and ensure that your OnClientClick = the name of the javascript function you want to call plus the word return in front of it as in the example asp
code shown in the original post.
Ensure you fire up the backend C# function as per usual for example by double clicking on the button or control in design view of Visual Studio 2012 or 2013 or whatever so as to automatically build its backend function in the code behind page and code your backend function for what you want it to do obviously.
When you have done step 3 correctly you should have OnClick= whatever your backend C# function was.
Test your application. Once your front end javascript returns true it should automatically fire up
your backend function as long as you have put a return statement as per the front end code shown in the original post or similar.
Life can be simple if only you want it to be. The choice is yours.

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"));
}

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