This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Jul 19, 2011, 9:10 PM
45 Posts
topic has been resolvedResolved

Send Document Link in Email from XPage

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: End user
  • Tags:
  • Replies: 4
Hi,
 
I am trying to replicate the traditional @Mailsend in XPages. Simple application, web user clicks a submit button and workflow email is sent to a group of Notes users' mail file.
 
I have this so far, but do not know enough about MIME and whether I should be somehow getting an RTitem in there to hold the 'appendDocLink(currentDocument)' If someone could add the correct code and provide a snippet of explanation that would be fantastic.
 
Many thanks
Mark   
 

db = session.getCurrentDatabase();

memo = db.createDocument()

memo.appendItemValue("Form","Memo");

memo.appendItemValue("Principal","Survey@NotesDomain");

memo.appendItemValue("From","useremailaddress");

memo.appendItemValue("DisplaySent","useremailaddress");

memo.appendItemValue("SMTPOriginator","useremailaddress");

textMail = "A survey has been completed click on the Doc Link to open it.";

body = memo.createMIMEEntity();

subject = body.createHeader("Subject");

subject.setHeaderVal("A Mobile Survey Form Has Been Completed");

stream = session.createStream();

stream.writeText(textMail);

body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);

memo.send("receiverEmailaddress");

   
Jul 21, 2011, 8:09 PM
31 Posts
Re: Send Document Link in Email from XPage
Hi Mark, there was a really great tutorial on the "MyAdvisor" site by Matt Holthe showing how to create various types of MIME emails, however I don't think it exists on the web anymore.  You can probably find some in the ddwiki or in the Notes 6 & 7 forum as well.
 
I'm not sure how or if you can generate a doc-link in MIME, but here's how you can generate a URL link (you should be able to instead use a "Notes://" link which would work like a doc-link in the Notes client instead of opening up the doc in a browser):
    Dim body As NotesMIMEEntity
    Dim mimeHeader As NotesMIMEHeader
    Dim mimeChild As NotesMIMEEntity
    dim stream As NotesStream
 
.... etc. ...
 
    ' -  Generated URL to link to Request document should be of the format ...
    ' >>  http://<server>/<dbPath>/<dbName.nsf>/$$OpenDominoDocument.xsp?documentId=<DocUNID>&action=openDocument
       
    webAddr         = Evaluate("@WebDbName",reviewDoc)  ' = dbPath & nsf name in URL format with forward slashes
   
    ' - db.HTTPURL = URL command to open database ...
    ' - strip off the "/__<replicaID>?Opendatabase" to just leave the server URL "http://<server HTTP host name>"
    urlLink             = StrLeftBack ( db.HTTPUrl, "/" ) + "/" + webAddr(0)  + "/$$OpenDominoDocument.xsp?documentId=" _
    +  reviewDoc.ParentUNID(0) + "&action=openDocument"

    If db.HTTPUrl = "" Then
        urlLink        = "http://localhost" + urlLink
    End If        
                                               
    urlLinkText     = "Click here to open Request: " + reviewDoc.RequestID(0)   
 
... etc. ....
 
    Set mimeHeader         = body.CreateHeader({MIME-Version})
    Call mimeHeader.SetHeaderVal("1.0")
    Set mimeHeader         = body.CreateHeader("Content-Type")
    Call mimeHeader.SetHeaderValAndParams( {multipart/alternative;boundary="=NextPart_="})    

    
    ' -  Generate the HTML part of the email body next ...
    Set mimeChild         = body.createChildEntity()
    Set stream             = session.createStream()
 
.... (Set all your styles & addresing & the content of your email etc.) ....
 
     Call stream.WriteText({<a href="} + urlLink + {">} + urlLinkText + {</a><br><br>})
    Call stream.WriteText("<hr>")
    Call stream.WriteText({<div style="font-size:9pt;text-align:center;">} + footerText + {</div>})    
           
    Call stream.WriteText("</body>", EOL_CRLF)
    Call stream.WriteText("</html>", EOL_CRLF)
    Call mimeChild.setContentFromText(stream, {text/html;charset="iso-8859-1"}, ENC_NONE)
    Call stream.Close()

then send the email ...
Hope that helps,
Judy.
 
 
Jul 21, 2011, 8:56 PM
45 Posts
Re: Send Document Link in Email from XPage
Many thanks Judy,
 
Is this right all this just to replace the '@Mailsend - inc Doc Link' in XPages we need all this? Just when I think I am getting somewhere with XPages!
 
Your sample appears to contain LotusScript, are we at cross purposes here?  The form I am using is in XPages  I just want to send an email to Notes client users with a doc link to the XPage when the user submits it. I am not really bothered about MIME, but thought that was the way to do it, with the lack of an @MailSend option. When would one use the 'appendDocLink()' method in javascript?
 
I will study your suggestions though, many thanks.  
Jul 22, 2011, 12:34 PM
31 Posts
Re: Send Document Link in Email from XPage
Hi Mark, I thought you were trying to create a MIME email.  They're really not that difficult -- once you create one MIME email, you'll find it's pretty easy.  I find they generally look more professional than strictly richtext emails, just my opinion.
 
You can run a LotusScript agent in the PostSaveDocument event (which is the way I did it in 8.5.1) -- I think now in 8.5.2 you can also get a handle to the in-memory document in the QuerySaveDocument event too.  You're right there's no @MailSend anymore in XPages.  But you don't have to run a LS agent; you can also write some Server-side Javascript using methods & properties that look a lot like LotusScript, take a look in the Help -- you should be able to just append a doclink to a richtext item via SSJS if that's your desire.  So you'd just need to create a virtual/temporary Form="Memo" document and add a "Body" RT field & create your email that way & then do a doc.Send at the end. 
 
Here's a snippet from the Help:

Syntax

appendDocLink(doc:NotesDocument) : void

appendDocLink(db:NotesDatabase) : void

appendDocLink(vw:NotesView) : void

appendDocLink(doc:NotesDocument, comment:string) : void

appendDocLink(db:NotesDatabase, comment:string) : void

appendDocLink(vw:NotesView, comment:string) : void

Parameter Description
Document doc The document to which you want to link.
Database db The database to which you want to link.
View vw The view to which you want to link.
String comment The text that appears when a user presses and holds the mouse over the link.
String hotspottext Boxed text which the user clicks to follow the link. This text appears in place of a token.


 
Aug 9, 2011, 8:55 PM
45 Posts
Re: Send Document Link in Email from XPage
Many thanks Judy your help is appreciated,  I have been on holiday hence the late reply.
 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal