How to Email include Notes link to open xpages client - xpages

I have problem when sending a notes link to an email in order to open it directly from email client. Does the link i created is invalid? May i know which is a correct way of sending notes link open xpages page?
Question 1. How to open Document in xpages with document ID by clicking notes link?
one way: i understand is at the form Display xpages. May i know still got other way to do it?
Question 2. How to open Xpages Page without document ID for example is like the page that contain view.
My doclink is write as:
var doclink="notes://"+server+"/"+dname.replace(/(\\)/g, "/")+"/"+document1.getDocument().getUniversalID()+"/Request_Form.xsp?OpenXpages"
result come out for that link:
My viewlink is write as:
var viewlink ="notes://" +server+"/"+dname.replace(/(\\)/g, "/")+"/"+"Request_View.xsp?OpenXPage"
result come out for that link:
My server and database name as below
Below will be my script of sending email
var setdoc:NotesDocument = database.getProfileDocument("System Setting", "");
var server = setdoc.getItemValueString("MailDBSvr");
var dname = setdoc.getItemValueString("MailDbPath");
var web = setdoc.getItemValueString("InternetAddress");
var maildoc:NotesDocument = database.createDocument()//mdb.createDocument() //database.createDocument()
maildoc.replaceItemValue("Form", "Memo");
maildoc.replaceItemValue("Subject","Request for Email Account By "+document1.getItemValueString('Name'));
session.setConvertMime(false);
var stream = session.createStream();
stream.writeText("<html><body>");
stream.writeText("<p>Dear " + "department reviewer" + ",</p>");
stream.writeText('<p>Kindly review this request by '+document1.getItemValueString('Name')+" on "+I18n.toString(#Today(), 'dd/MM/yyyy')+ ",</p>");
// open in web (http://devsvr1.pcs.com.my/CN=ServerOne/O=dev!!Brooke%5CBrooke.nsf/Request_Form.xsp?databaseName=CN=ServerOne/O=dev!!Brooke%5CBrooke.nsf&documentId=5FBA577C3DF795AB4825819400274B0A&action=editDocument)
stream.writeText("<p>Please click "+"<a href='http://"+web+"/"+
database.getServer()+"!!"+
XSPUrl.encodeParameter(dname, "UTF-8") +
"/"+"Request_Form.xsp?databaseName="+server+"!!"+
XSPUrl.encodeParameter(dname,"UTF-8") +
"&documentId="+document1.getDocument().getUniversalID()+
"&action=editDocument'>here</a> to open requisition form</p>")
// open in notes client (notes://server/path/database.nsf/pagename.xsp?openXpage)
var doclink="notes://"+server+"/"+dname.replace(/(\\)/g, "/")+"/"+document1.getDocument().getUniversalID()+"/Request_Form.xsp?OpenXpages"
stream.writeText("<p><a href='"+doclink+"'>Click Here</a> if you are in the Notes Client. Thank you.</p>");
stream.writeText("<p>Or</p>");
// open in web (http://devsvr1.pcs.com.my/brooke/brooke.nsf/Request_View.xsp)
stream.writeText("<p>Click <a href='http://"+web+"/"+dname.replace(/(\\)/g, "/")+"/"+"Request_View.xsp?'>here</a> to view all requisitions.</p>");
// Open in notes Client
// #URLOpen("notes://server/Path/database.nsf/XPageName.xsp?OpenXPage")
var viewlink ="notes://" +server+"/"+dname.replace(/(\\)/g, "/")+"/"+"Request_View.xsp?OpenXPage"
stream.writeText("<p><a href='"+viewlink+"'>Click Here</a> if you are in the Notes Client. Thank you.</p>");
stream.writeText("<p> ***THIS IS AN AUTOMATED MESSAGE - PLEASE DO NOT REPLY DIRECTLY TO THIS EMAIL***</p>");
stream.writeText("</body></html>");
var body = maildoc.createMIMEEntity("Body");
body.setContentFromText(stream, "text/html;charset=UTF-8", 1725);
stream.close();
maildoc.closeMIMEEntities(true);
session.setConvertMime(true);
maildoc.replaceItemValue("SendTo",document1.getItemValue("Dep_rev"));
maildoc.send();
document1.getDocument().computeWithForm(true,true);
New update:

You need to change the way you handle the server name. Notes URLs don't use the full canonical name for servers.
So change CN=ServerOne/O=Dev to something the notes:// protocol does support. You could use:
the shortened name ServerOne%2FDev (use #Name[Abbreviate] and replace / with %2f)
the Common name ServerOne (use #Name[CN])
the DNS name www.yourserver.com
the IP address: 165.34.11.34
In all cases you need to make sure that the server name gets properly resolved by the Notes client:
For the shortened name a connection document would do the trick (unless its the default server, then it is auto).
For the Common name it is either a connection document or the DNS resolved it (intranet DNS)
for the DNS name, its DNS (doh)
You really don't want to use IP addresses, but you could
Hope that helps

Related

How can I transfer a file from Gmail using an app script by POSTing to a remote server

I'm using google apps scripting to write some addons to link gmail (or g suite email) to our crm system.
My current issue is trying to take a selected attachment, POST to a php script on a remote server which recreates the file (and goes from there to integrate into our crm).
Details of the code etc is below though in essence the file obviously isn't transferring correctly so something is wrong in the way the file is being received, or saved locally. The filesize is different and it won't open. So for example I select a PDF in the email which is 640k and the resulting file created on my server is over 1mb
I've setup my script with a card which includes a radio list of attachments. A button in the card attempts to post the file contents to the remote server where a receiving PHP script just saves it as a local file.
Getting attachment list to produce radio buttons:
var attachmenttosave = CardService.newSelectionInput().setType(CardService.SelectionInputType.RADIO_BUTTON).setTitle("Selected Attachment").setFieldName("attachmenttosave");
for(var i = 0; i < attachments.length; i++) {
var attachment=attachments[i];
attachmenttosave.addItem(attachment.getName(),i,false);
}
code which gets the attachment and POSTs to remote server:
var accessToken = e.messageMetadata.accessToken;
var accessToken = e.messageMetadata.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);
var messageId = e.messageMetadata.messageId;
var message = GmailApp.getMessageById(messageId);
var atc=e['formInput'].attachmenttosave;
var attachments=message.getAttachments();
var fn=attachments[parseInt(atc)].getName();
var blob=attachments[parseInt(atc)].getAs(attachments[parseInt(atc)].getContentType());
var url="https://remote.server";
var payload={"typ":"GS_SaveAttachmentToCase","email":encodeURIComponent(user),"fn":encodeURIComponent(fn), 'att':(blob)};
var options={"method":"POST","payload":payload,"followRedirects":true,"muteHttpExceptions":true};
var result=UrlFetchApp.fetch(url, options);
var data = result.getContentText();
return CardService.newActionResponseBuilder().setNotification(CardService.newNotification().setText(data).setType(CardService.NotificationType.INFO)).build();
Receiving PHP script:
`
function GS_SaveAttachmentToCase(){
$fn=urldecode($_POST['fn']);
$fp = fopen("GS/" .$fn, "w+");
fwrite($fp, (utf8_decode ($_POST['att'])));
fclose($fp);
echo "done";
}
`
ok did some more research and solved this.
get the attachment contents using
blob=attachments[parseInt(atc)].getBytes();
in the receiving php script
fwrite($fp, (base64_decode ($_POST['att'])));

How to download documents from liferay from outside application ..using liferay jsonws or any other way

Hi i am using liferay/api/secure/jsonws services to upload documents, getting documents, from a outside application , in the same way i want to download the documents also, i checked my liferay jsonws , there is no method or service which i can use for download , or i don't know about it , please suggest me a way to download documents from outside application , by using jsonws or any other way is also fine.
Edit after i got to know how to download document.
Hi I tried to download liferay document from outside application by using getURl, but every time for all document i am getting liferay login page content
i have already tried get-file-as-stream json-rpc call but that also giving me null response
the code which i have used is:
final HttpHost targetHost = new HttpHost(hostname.trim());
System.out.println(targetHost.getHostName());
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
System.out.println(creds);
final AuthScope authscope = new AuthScope(targetHost);
httpclient.getCredentialsProvider().setCredentials(authscope, creds);
final AuthCache authCache = new BasicAuthCache();
final BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
final BasicHttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
final HttpGet httpget = new HttpGet(hostname+"/documents/" + groupId + "/" + folderId + "/" + filename);
final HttpResponse response = httpclient.execute( httpget, localContext);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
final org.apache.http.HttpEntity entity = response.getEntity();
if (entity != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
entity.writeTo(baos);
return baos.toByteArray();
}
}
return null;
} finally {
httpclient.getConnectionManager().shutdown();
}
}
i am adding basic auth header will correct username and password, don't know how this login page is coming, is there any permission which i need to change or any configurations issue, please help in this.
You could use the Liferay WebDav Services to download files from your document-library. The paths to download can be inspected inside of the control-panel when clicking on a file entry (WebDAV URL toogle link). The paths usually look like: /webdav/{site-name}/document_library/{folder-name}/{file-name}
Otherwise, you could mimic the request URLs Liferay creates inside the documents-media portlet to download the file entry.
But you should take care about authentication, when your files (and folders) are not visible to guests.

How do i send a doclink when sending new mail in SSJS using XPages?

Previously i am sending a form as a doclink using #functions
Eg: #MailSend("Mary Tsen/";"";"";"Follow this link";"";"";[IncludeDocLink])
Please tell me how to send a mail message that includes a doclink in XPages using Serverside JavaScript.
thank you
The concept of a doclink in a web application don't exist. Therefore you must create an email and include a URL to the specific element. Not sure if using XPINC allows adding of a doclink.
email = database.createDocument();
email.replaceItemValue("Form", "Memo");
email.replaceItemValue("Subject","Test");
email.replaceItemValue("Body","You have email");
email.replaceItemValue("SendTo", sendto);
email.send(false);
In the past what I have done to include a link was to reconstruct the URL, as shown below, for the XPage and add that to the body of the message.
I used a viewPanel link for my scenario, but this should get you down the proper path.
var url:XSPUrl = context.getUrl();
var doc:NotesDocument = row.getDocument();
var unid = doc.getUniversalID();
var scheme = url.getScheme();
var host = url.getHost();
var db = database.getFilePath();
pdfurl = scheme + "://" + host + "/" + db + "/0/" + unid;
You can add a doclink to a rich text item using something like the code below.
var docEmail:NotesDocument = database.createDocument();
var rtitem:NotesRichTextItem = docEmail.createRichTextItem("Body");
docEmail.replaceItemValue("Form", "Memo");
docEmail.replaceItemValue("SendTo", "Your recipient");
docEmail.replaceItemValue("Subject", "Your Subject");
rtitem.appendText("Some text here... ");
rtitem.addNewLine(2);
rtitem.appendText("Click here to view the document => ");
rtitem.appendDocLink(thisdoc, "Some comment text");
rtitem.addNewLine(2);
docEmail.send();

How do I post from Instagram to a Squarespace blog?

After a good amount of research today I figured it would be helpful if I wrote up what I have found to be a solid way to get Instagram posts automatically, not into a block, but directly into your blog on your foursquare blog (or other blogs that accept posts from email).
Prerequisites: A Gmail Account, and IFTTT account
Firstly in the settings for your blog turn on post by email. Then set up a trigger at IFTTT.com. The trigger is if a new photo is posted to your instagram send an email from your Gmail. The trigger is then set up to send the email to your GMail, subject can be whatever you'd like, I chose instagram: the body of the email is:
{{SourceUrl}} {{Caption}}
You then create a google script at script.google.com the script is: (must modify depending on your email address, subject you chose for email, and the email address you must send to for posting to your blog).
function sendCorrectEmail() {
var instagramThreads = GmailApp.search('from:(justinhenricks#gmail.com) to:(justinhenricks#gmail.com) subject:(instagram:)', 0, 25);
for(var i = 0; i < instagramThreads.length; i++) {
var messages = instagramThreads[i].getMessages();
for(var j = 0; j < messages.length; j++){
var body = messages[j].getPlainBody();
var urlEndIndex = body.indexOf(" ");
var url = body.substring(0, urlEndIndex);
var content = body.substring(urlEndIndex + 1, body.length - 1);
var newBody = "<center><img src='" + url + "' /><br /><br /><i>instagram: </i>" + content + " </center>";
GmailApp.sendEmail("pbm+justin-henricks+j4p937#squarespace.com", "", newBody);
}
}
//delete all threads
if(instagramThreads.length > 0) {
GmailApp.moveThreadsToTrash(instagramThreads);
}
};
Of course format the HTML to whatever you seem fit. The script simply checks your email for emails sent by you, to you, with a subject of instagram: it then takes the body of the email if it found one and separates the img URL from the content, it then formats those two variables into a little bit of HTML and sends a new email out to the address accepted by your blog.
Lastly, you're going to want to click Resources on the google script and add a trigger for the method to be executed every x amount of time. That way it will continuously check if there has been new instagram posts, and it will post them automatically.
I spent a few hours on this and although at first there seemed like there were less complicated ways to achieve this, there turned out not to be. If you are content with simply having a separate instagram block on your site SquareSpace can do this for you. I wanted my blog to contain my blog posts, and instagram posts all in one. This script can also very easily be modified to handle Twitter, Facebook etc all you would need to do is set up different IFTTT triggers and write new methods. Good luck!

Xpages get mail file from lotus

Is there a way to get the value of the mail file field from the (Company)' Directory ? I wrote a code to get the value but it is not the same in all situation.
Here is the code:
var firstChar = context.getUser().getFullName().charAt(0);
var lastWord = context.getUser().getFullName().split(" ").pop();
var str = firstChar+lastWord;
var str2 = str.slice(0, 8);
var link = "https://server/mail/";
link +=str2+".nsf/iNotes/Mail/?OpenDocument&ui=portal";
return link;
You can access the server directory as any other Notes database. Unless additional address books are there, the user should exist under their username in the "($Users)" view. From there you can retrieve the mail file and server. If it's different from the current server, you may need to check the relevant server document for the hostname.
Borrowing an example from the documentation on the NotesDirectory class and modifying for your purposes, I'd try something like:
var mynotesdir:NotesDirectory = session.getDirectory("server name");
var homeserver = mynotesdir.GetMailInfo("Joe Smith", True);
var mailFileName = homeserver[3];
var link = "https://server/mail/" + mailFileName + "/iNotes/Mail/?OpenDocument&ui=portal";
return link;
The syntax may be wrong, as I copied it from an example and modified it here instead of in Designer, but this should still serve as a good start.....

Resources