Document Link in Xpages based application for Rich and Web Client - xpages

I am looking for best way to compose an email and attach document link for notes and web client using SSJS.
We are doing it one way but I think there is some good way of doing this. I want to use complete functionality of Rich Text Item e.g. formating, styles and other which we normally do in LotusScript.
Any sample application having industry standard way of doing this will be great help.
Following is sample code how we are doing right now.
var stream = session.createStream();
stream.writeText("Application is forwarded to you for approval. ");
var var3 = '<a href =' + notesDocLink + '> Open in Rich Client (Doc Link) </a>'
var var4 = '<a href =' + webDocLink + '> Open in Internet Explorer </a>'
stream.writeText( var3 + " For web Client Use this link: " + var4 , 2);
stream.writeText("Note: This is auto-generated email and do not require any reply. ");
mailBody.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
mailDoc.replaceItemValue("SendTo",mailSendTo);
mailDoc.replaceItemValue("CopyTo",mailCopyTo);
mailDoc.send();
I am interested in something like this which is currently not working for me.
mailDoc.replaceItemValue("Form","Memo");
mailDoc.replaceItemValue("Subject" , strSubject);
var RTItem:NotesRichTextItem = mailDoc.createRichTextItem("Body");
RTItem.appendText("Leave Application is forwarded to you for approval. ");
RTItem.addNewLine(2);
RTItem.appendText("Please click on below document link for details. ");
RTItem.appendDocLink(currDoc, "Click on Link to Proceed")
RTItem.addNewLine(2);
RTItem.appendText("Note: This is auto-generated email and do not require any reply. ");
RTItem.addNewLine(2);
mailDoc.replaceItemValue("SendTo",mailSendTo);
mailDoc.replaceItemValue("CopyTo",mailCopyTo);
mailDoc.send();

For doc links, please confirm that the answer to this question doesn't solve your problem Getting an Error message when trying to appendDocLink is SSJS.
There are a couple of code examples for emails on XSnippets:
Mark Leusink's creation of email as MIME http://openntf.org/XSnippets.nsf/snippet.xsp?id=create-html-mails-in-ssjs-using-mime
Tony McGuckin's emailBean: http://openntf.org/XSnippets.nsf/snippet.xsp?id=emailbean-send-dominodocument-html-emails-cw-embedded-images-attachments-custom-headerfooter
For anyone using the OpenNTF Domino API, this has a DominoEmail class, for creating an email as well.
In R9 there is also a Send Mail simple function.
Personally, I'd prefer HTML and MIME for styling compared to the RichTextStyle classes. It also gives greater flexibility for web links as well as client. It has the added benefit of fidelity when sending outside Notes. Even for Notes users viewing on mobile devices via Traveler, I think the Traveler server will have to convert to MIME to ensure the styles are available, so it's easier to cut out that step by using MIME for a start.

Related

Hyperlink in response in Api.ai

I am exploring api.ai now a days for one assignment to develop chat bot. Is there a way to add hyperlinks as a part of default response? I do not want to use Google Assistant, Facebook Messanger, KIK,Slack etc but I want to include hyperlink as a part of Default Response. I explored various blogs but could not find desired answer.
Practically you can't, but there is a hack:
Choose the response to be card.
Choose a custom image.
Embed link in the "next".
No, ideally you can not add a hyperlink in default response of api.ai but there is a workaround that I used in my code. In my case, I have developed my own chat window where before printing, I'm running a check on the response that is coming from api.ai using following function & get that link converted into the clickable format.
if(!String.linkify) {
String.prototype.linkify = function() {
// http://, https://, ftp://
var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&##\/%?=~_|!:,.;]*[a-z0-9-+&##\/%=~_|]/gim;
// www. sans http:// or https://
var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
// Email addresses
var emailAddressPattern = /[\w.]+#[a-zA-Z_-]+?(?:\.[a-zA-Z]{2,6})+/gim;
return this
.replace(urlPattern, '<a target="_blank" href="$&">$&</a>')
.replace(pseudoUrlPattern, '$1<a target="_blank" href="http://$2">$2</a>')
.replace(emailAddressPattern, '$&');
};
}

base64 images not displaying in Outlook when using ejs + emailjs

I'm using a mix of ejs and emailjs to send out emails in my node.js app when various events happen. I'd like to embed a base64 image (a small logo) into the email when it sends, but both Outlook and Gmail (plus Inbox by Google) fail to render the image.
I'm using this bit of code to find the mime type of the image and put together the base64 string:
MyApp.prototype.ImageToBase64 = function(image) {
var mime = require("mime")
file = fs.readFileSync(__dirname + "/images/" + image, { encoding: 'base64'})
return 'data:' + mime.lookup(image) + ';base64,' + file;
}
That works great, because I'm able to copy and paste that resulting string right into my browser and see the image. But when I send the email via emailjs, Outlook converts the +s to +. When I "View Original" in Gmail, the base64 is split up into 'chunks'. Each chunk is on a newline and each line ends with a =. If I take Gmail's version and remove the = and newline then paste it into my browser, the whole picture loads perfectly, but it just refuses to load anywhere else, regardless of whether the user is in my contact list or not.
Here's the code I'm using to send the email:
// Host, username, password and SSL (false) all set above here
server.send({
text: myTemplate,
from: "me#example.com",
to: "someone#example.com",
subject: "Testing",
attachment: [
{data:myTemplate, alternative:true}
]
})
And the template looks like this (truncated, as the other bits aren't important):
<body>
<p><img src="<%- ImageToBase64("logo.png") %>"></p>
<h1><%= Name %> has been triggered</h1>
<p><%= Name %> has been triggered. It was triggered on <%= TheDate %></p>
Any hints?
EDIT: I tried setting the headers in the "attachment" property, but with no luck
Outlook uses Word to render the images, and Word does not support embedded (src="data:image") images.
You need to attach the image as a file and set the Content-ID MIME header to the value matching the cid attribute on the image (<img src="cid:xyz">) in the HTML body.
Okay, so even though this answer is from 2013, it seems like the wisdom still holds true, in that base64 image support sucks in email clients.
Basically the only mail clients that still support inline images are either older ones (e.g. Office 2007), or Apple / Android's default mail apps.
While that's a bit disappointing, it's not the end of the world, as the email will only be seen by people on the same network as my app, so I can just point to the image hosted on the web portion of the app.
But for anyone else trying this, host your image on an image sharing site like Imgur or on your own server and use a regular ol' <image> tag to display it.
So much for self-contained emails, right?

Attaching a file generated via POI to a notes document

I need to attach a file generated by Apache POI on an Xpage to a notes document. I have been attempting to implement a solution as suggested by Knut Herrmann:
var temp = java.lang.System.getProperty("java.io.tmpdir");
var file = new java.io.File(temp + "YourFile.docx");
var fileOutputStream = new java.io.FileOutputStream(file);
xwpfdocument.write(fileOutputStream);
fileOutputStream.close();
var doc:NotesDocument = currentDocument.getDocument();
var rdoc:NotesDocument = database.createDocument();
rdoc.appendItemValue("Form", "frmRespTempl");
rdoc.appendItemValue("Subject", "Embedded Word Document");
var rtitem:RichTextItem = rdoc.createRichTextItem("Body");
rtitem.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT,"",file.getAbsolutePath(), null);
rdoc.makeResponse(doc);
rdoc.save();
POI for XPages - save Word document as attachment in rich text field
however, in order to make xwpfdocument.write(fileOutputStream) work, the java policy file needs to be modified which is a security risk.
I had no luck making the java solutions work either. Is there any other way to go about making this code work? What exactly is the risk of modifying the java policy?
Thanks
Are you running the code in a browser or in the Notes Client because the code will never work in a browser if you want to send the file to the user side. It will work on the serverside.
If you want to attach a local document in a Notes client I would suggest you start an Notes agent with the code to embed the file instead.
Instead of modifying the java.policy file, I think you could
write a class that you implement inside a jar file and place that jar file in the class path on the server and instance it from your XPage code.

Sending email through AJAX calculated column

I'm trying to send an automatic email receipt for items that have been created on a sharepoint list.
Conditions
I cannot use workflows - they are disabled
I cannot use webparts - they are disabled
I cannot use sharepoint designer etc etc etc - they are all disabled
The function needs to be OOTB
The only option I have is using javascript in calculated columns. I am aware of the use of the HTML:mailto tag - but this opens Microsoft outlook, and is not automatic.
Came across this link:
http://geekswithblogs.net/ThorvaldBoe/archive/2014/07/03/sending-email-with-sharepoint-and-jquery.aspx
So, here is the calculated column attempt:
="<button onclick=""{function SendEMail(from, to, body, subject){"
&"var siteurl = _spPageContextInfo.webServerRelativeUrl;"
&"var urlTemplate = siteurl + '/_api/SP.Utilities.Utility.SendEmail';"
&"$.ajax({"
&"contentType: 'application/json',"
&"url: urlTemplate,"
&" type: 'POST',"
&"data: JSON.stringify({"
&"'properties': {"
&"'__metadata': { 'type': 'SP.Utilities.EmailProperties' },"
&"'From': from,"
&"'To': { 'results': [to] },"
&"'Body': body,"
&"'Subject': subject"
&"}}),"
&"headers: {"
&"'Accept': 'application/json;odata=verbose',"
&"'content-type': 'application/json;odata=verbose',"
&"'X-RequestDigest': $('#__REQUESTDIGEST').val()"
&"},success: function (data) {"
&"alert('Eposten ble sendt');"
&"},error: function (err) {"
&" alert(err.responseText);"
&" debugger;}});}"
&"SendEMail('user#whatever.com','user#whatever.com','Test1','Test2');}"">"&"Send</button>"
When running the code, the Console shows the following error: '$' is undefined
Any suggestions on how to overcome this?
Thanks
You keep raising the bar, Steve!
You're really making it difficult for yourself this way
I suggest the next learning steps first:
Learn all about Chrome Snippets
this will help you develop/execute code directly on the View page without the need for stuffing it in a Calculated Column or any script in SharePoint
Learn jQuery (by using Snippets)
check out jQuerify it will inject jQuery where it is not available
[optional] Learn Tampermonkey
this will help in immediatly executing your scripts on a SharePoint page (without the need for including the script in SharePoint
Learn JSOM Ajax calls and REST Ajax calls (REST is halfbaked implemented in 2010)
again; do them in Snippets first
When that all works you're halfway done and you can wrap it all in the Calculated Column (again, this is all undocumented hacking away at Microsoft technology, if they decide to make changes in an Update you're cooked... e.g they disabled the use of the SCRIPT tag in summer 2013; that's why you now have to use the blank IMG onload trick
Note: I have updated my CalcMaster BookMarklet on GitHub. Once you have your Snippet working you can paste it in an existing Calculated Column Formula and wrap it in IMG onload and &".." notation with one click
If you get that sending email working let us know; I have never done it... I stay away from projects where SharePoint Designer can not be used.
Once you have mastered all the above you will have learned so much Front-End development I suggest you go look for another job.

xpages forward o reply email

I need a solution, that when you press a button from a inbox xpages mail message, the new xpages is composed with the body and image and attachment of original inbox message (ckeditor control)
I nave found a Solution for passing HTML to ckeditor but not for attachment and inline image.
Have you any suggest?
P.S. the solution will need work in on-fly mode (without savind document before..so that when you foward an email with a classic webmail)
See my answer below on how to copy contents and images to a CKEditor on the fly:
https://stackoverflow.com/a/19328276/785061

Resources