0

How to create a text file in project folder and i need to send this file as email attachment. Then i need to delete this file.

var textBuffer="BEGIN:VCALENDAR\r\nVERSION:2.0\r\n...END:VEVENT\r\nEND:VCALENDAR";

file = new java.io.File("c:\\Notes\\sample.ics");

//Create the file
if (file.createNewFile()){

print("File is created!");

}
else{

print("File already exists.");

}

//Write Content
writer = new java.io.FileOutputStream(file);

writer.write(textBuffer.getBytes());

writer.close();

var db:Database  = session.getDatabase("server name", "database name", false);

var doc:NotesDocument = database.createDocument();

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

var nMime:NotesMIMEEntity = doc.createMIMEEntity();

var mimeHeader:NotesMIMEHeader;

mimeHeader = nMime.createHeader("To");

mimeHeader.setHeaderVal("email id");

mimeHeader = nMime.createHeader("Subject");

mimeHeader.addValText("Test Email", "UTF-8"); 

var stream:NotesStream = session.createStream();

var pathname:string = "c:\\Notes\\sample.ics";

if (stream.open(pathname, "binary")) {

    nMime.getContentAsBytes(stream);

    stream.close();

    }

nMime.setContentFromBytes(stream, "text/plain; charset=\"UTF-8\"",NotesMIMEEntity.ENC_NONE);

doc.send();

session.setConvertMIME(true);

After this code is excuted i am getting a mail but there is no attachment. Please help me to find what went wrong in this code.

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
Arun Raj
  • 85
  • 1
  • 7
  • 1
    What have you tried so far? and where did you get stuck? https://stackoverflow.com/help/how-to-ask – Per Henrik Lausten Aug 10 '18 at 07:48
  • I am able to create the file using response.getOutputStream().write(textBuffer.getBytes()); method but i need to write this file in to a specific folder in my project – Arun Raj Aug 10 '18 at 08:15
  • I just need to create a file in my project path folder using ssjs. I am new to SSJS. – Arun Raj Aug 10 '18 at 08:41
  • 1
    What is "project folder"? Is it accessible from Domino? And why you want to create it there, then delete it? – Frantisek Kossuth Aug 10 '18 at 10:22
  • It is always problematic if you just copy n paste code from somewhere else without knowing what it does: https://stackoverflow.com/questions/35868865/xpages-to-create-txt-file-via-ssjs#35869888 – Sven Hasselbach Aug 10 '18 at 16:10
  • @SvenHasselbach this is first time i am seeing SSJS and lotus note. Thats why i am not sure how this thing works. – Arun Raj Aug 13 '18 at 05:00
  • @FrantisekKossuth For eaxmple i need to create this text file in the webcontent folder of the lotus note application. – Arun Raj Aug 13 '18 at 05:01

2 Answers2

0

There are 2 potential answers to your question:

a) with “project folder” you refer to a folder on your local machine (the one running the browser): for security no Webserver can specify the download location. It is a browser setting. That’s for security. It would be too easy to damage a user’s workstation. The only way is when you control the browser - which might work for an integration user, but not a user base.

b) “Project folder” is a location on the server (the machine running Domino). There you instantiate a FileOutputStream (a Java Object) and do the same. SSJS can use Java classes.

If you share why you need this, a better solution can be proposed.

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • The exact need is to write some content as text file and sent this text file as attachment via mail. Can we store the text file in a document? – Arun Raj Aug 13 '18 at 04:56
  • That’s your perception of the requirement. The real one is: create something that gets emailed and received as email with an attachment – stwissel Aug 13 '18 at 11:04
0

You need a complete different approach: - check the Mime classes in Notes - create a multipart mime document - write your text data into a mime part flagged as attachment

No creation of a file required. See also this answer: When generating HTML email using MIME, can attachments be displayed in the Lotus Notes email body?

If you insist of creating a physical file: you need to store it on the server FileOutputStream style, since the server side attach function doesn’t have access to your local file system

stwissel
  • 20,110
  • 6
  • 54
  • 101