How to connect to outlook from browser (internet explorer) - javascript

So this is what I need for my customer
From my secure intranet webapplication the user can select several files. Somehow (browser plugin/add-on, JavaScript, whatever) the user can start outlook to compose a new mail. The selected files have to be attached to the composed mail. To make things even more interesting, the filenames of the attached files have to be altered (the file version has to be added to the filename).
It must work with Outlook 2013 and Internet Explorer 11.
I don't want the mail to be created in the browser and then be send from the server, since I want the user to have full control on the composed mail and have them use all the features of Outlook.
What would be the right technique(s) to accomplish this?

Dynamically create an EML file (MIME) and give the user a link to it. Outlook will be able to open the message with the HTM body, recipients, attachments, etc. prepopulated.

Try to use this into your javascript
mailto:email#domain.com?subject=file&body=P.F.A&attachment='filepath/filename.extention'

Related

How can I get the actual file path of the selected file in Chrome instead of the 'fakepath'? [duplicate]

This question already has answers here:
How to resolve the C:\fakepath?
(13 answers)
Closed 3 months ago.
After selecting a file in Chrome I need to get the full client side path to that file. Currently, the only path I get is something similar to:
C:\fakepath\some_file
All my googling lead me to the following answer: "you can't because of HTML5 security spec. Besides, why would you need to? You can upload it just fine without knowing the path."
This is a perfectly fine and valid answer except that I don't need to upload the file. The website I am managing can have any number of administrator users that configure the website by browsing for and storing paths to a large number of files. All these files are stored on shared network locations that the web server has access to.
The whole point of this is to eliminate upload time, to prevent the need to re-upload the files if the admins decides to change them and to keep the web server storage space to a minimum. Obviously, the web server also processes and manipulates these files. These are all client requirements.
The web server and the shared locations are all on an internal network not connected to the internet. Also, only the users with admin role have access to said locations and to the web pages that allow them to configure these paths. Security wise, this is enough for the client.
We've been using Internet Explorer and by adding the website to the trusted website list it worked just fine but now users are switching to Chrome, the new official and approved company browser. Internet explorer will soon be phased out.
Currently, users are copying and pasting the path into the input field but they want to be able to browse for the file as they did before.
How can I force Chrome to show me the actual file path, is there any equivalent to the trusted websites list from IE or how would you adapt the website to work with these conditions?
For security reasons browsers do not allow this, i.e. JavaScript in browser has no access to the File System.
You could build a chrome extension, see https://developer.chrome.com/docs/extensions/reference/fileSystem/
You can also open chrome with the flag --allow-file-access-from-file, see https://cmatskas.com/interacting-with-local-data-files-using-chrome/
The FileSystem API gives you a sandboxed file system created just for your web app.

Adding an attachment to default email client from client side

I tried to create a new mail with an attachment using mailto. It is opening a new mail window in Outlook 2010 but without attachment. While investigating the issue I understood that it is impossible to achieve using mailto. Is there any other way to achieve it? I researched about it but I couldn't find anything useful.
In Java Script?
If you are running inside IE from a trusted site, you can create an instance of the Outlook.Application COM object and use OOM to create a message with attachments.
You can programmatically build an EML (MIME) file that includes HTML body and attachments and let user download that file. Outlook will be happy to open an EML and display it to an end user.

Save email to outlook folder using ActiveXObject or Office Javascript API?

In outlook, there is a feature “Home page address” of folder through which we can view web site within the outlook. If we set http://app.abctest.com in the Home page address of a folder, then when we click this folder in the outlook, it will display that page.
I have a very specific requirement for enabling end user to browse a web site (in my case, it basically lists some archived emails) within from the Outlook. This can be easily done by setting the “Home page address” in the properties windows of any Folder of Outlook.
The user will see the page within outlook. He can search the old archived emails in the page. Then, the users should be able to download that email and save it to a folder in outlook. End users are basically searching the emails within outlook and downloading them from the server directly to their outlook folder. When user click the download\save link or button, then the outlook’s “Select Folder” dialog should appear where user can select the destination folder. When user click “OK” button, that email should be save to the selected folder in the outlook.
Currently, I have very few solutions but not sure if they can achieve the goal.
Solution 1: ActiveXObject
I tried to use Outlook ActiveXObject in javascript (used the following code in my test page) but I got the following Script error Popup message.
“Automation server cannot create the object”.
Javascript code:
var objO = new ActiveXObject('Outlook.Application');
Solution 2: Javascript API for Office
I have started to read the MSDN documentation https://msdn.microsoft.com/en-us/library/office/fp142185.aspx but have not got any sample code.
Could someone please sheds some light on it? Or what would be the best solution for this? Or any alternative solution.
Prakash,
Only one instance of Outlook can be run at the same time. Try to use the GetObject function instead to get the running Outlook instance instead. See How to programmatically create an Outlook home folder page in the Outlook Today style for more information. However, home page scripting is limited and secured to prevent malicious software. I'd suggest developing an add-in which can add a custom form instead.
The second solution listed above is for Mail Apps. See How to: Create your first mail app for Outlook by using Visual Studio for more information.
When your script runs inside a folder home page, window.external.OutlookApplication will point to an instance off the Outlook.Application object - your should be able to use it without creating a new object.

File upload with Javascript in chrome or firefox extension without user intervention

I've managed to get the element of a button inside a a webpage . I know its ID , its class , etc ; I even managed to trigger the click event from within a content script from a Google Chrome extension . The button is inside a Google webpage.
There's a Browse button though that opens up a openDialog window and prompts the user to chose a certain file for uploading. How can I go on automating this upload without prompting the user for the file? I just want to feed it the string from the content script and the webpage takes it from there.
Is there a solution for this in Google Chrome, Firefox?
Thank you!
if you are uploading from the clients computer, you can't. Its a security feature of file.upload. If you examine the path to the uploaded file, you'll notice c://fakepath/xxxxx this is to prevent applications finding out file structure on the clients computer.
https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
In Firefox add-ons (well, in the privileged parts, i.e. not SDK page-mods and so on), you can construct a file object you could use with the regular HTML5 stuff (XMLHttpRequest, FormData ;)) directly via the File "constructor":
var file = File("path/to/some/file");
When it comes to Chrome you're out of luck as #David already correctly pointed out in the other answer.
Edit 1:
Actually, when it comes to chrome it might be possible to request a file://* permission, have the user opt-in explicitly, and then use xhr etc. to first retrieve the file as a blob and then upload the blob with another xhr. Haven't tested this, though.

how to open csv file in IE in by javascript

In my asp page, I have to open a csv file in IE by java script. The code which I am using is as below:
csvWindow = window.open("/com/csv/"+csvFileName, "datacsv", "toolbar=yes,location=no,directories=yes,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=790,height=450,screenX=50,screenY=25,left=50,top=25");
Code is running in IIS server.
When I run this code and open csv file it gives below message
Microsoft Office Excel cannot access the file
"http://192.168.3.228:107/com/csv/CSV_file_1345728.csv". There are several possible reasons:
The file name or path does not exist
the file is being used by another program
the workbook you are trying yo save has the same name as a currently open workbook.
But file is being created.So path is correct and i think that file is also not used by another program
Please help me what should I do
The problem is that when Excel is opened it will attempt to fetch the CSV file itself, this a change in behaviour in office apps since 2007. However since Excel runs in a different process it will not send any cookies that would have been generated during the logon. When the website receives the request it will respond with a 401 status.
There are no easy solutions that I know of with entirely satisfactory results. Here are a number of solutions but all have drawbacks.
Make the authentication cookie persistent, this will allow Offices apps to pick up and send the cookie. The down side being the user remains persistently logged even after a client machine reboot (much like how Stackoverflow appears to work).
Use a standard HTTP authentication protocol like "Basic" or "Negotiate". The down side is that this will cause Excel to display a logon box and the user has to logon again. One exception to this drawback is using "Negotiate" or "NTLM" against an IIS box where the site is registered as part of the IE's Intranet Zone, in which case the HTTP stack used by excel will attempt to use the current user credentials.
Have a server side script that can run anonymously send the csv file and include in the URL some unique ID (such as GUID) which is a one off grant of access. Much more complex to set up.
If you want to open the file with MS Excel, you could try not to serve the file directly, but write an ASP page with Content-Type=application/force-download, the real file name ending with .css and the actual file content. In this case, MSIE will first download the file to the local disk cache and then will feed it to MS Excel.
If you just want to show the CSV text in the browser window, maybe the best is to change its extension or to make some proxy page with Content-Type=text/plain and no mention of CSV at all. The association CSV/Excel seems to be hardcoded in MSIE.

Categories

Resources