1

My xpage has following fields

  1. Xpage with evo:InputRichtext ckeditor from this snippet:
  2. I'm using gmail api to send email.
  3. I'm adding formatted text, inline images and files in Ckeditor
  4. Using button to get values from To, Subject and Ckeditor component using csjs.
  5. Message sent thru gmail server but not receiving wysiwyg format. The image is not displayed and only file name appears.

I know it is cross platform encoding issue and I don't know what is that.

Here is button code:

var to = XSP.getElementById("#{id:To}").value;
var subject = XSP.getElementById("#{id:Subject}").value;
var richCKEditor = CKEDITOR.instances["#{id:inputRichText1}"]; 
var dt=richCKEditor.getData();
var content = richCKEditor.dataProcessor.toHtml(dt);

 console.log(to);
 console.log(subject);
 console.log(content);

var email ="From: 'm' <"+to+">\r\n"+
"To:  "+ to +"\r\n"+
"Subject: "+subject+"\r\n"+"\r\n"+
"MIME-Version: 1.0\n"+
//"Content-Type:  text/html; charset=\"UTF-8\"\n" +
"Content-Type:  multipart/mixed; \n" +
content;
console.log(email);
auth();
send(email);

Here gmail api function I'm using with existing authentication from gmail api site

function send(email) {
console.log(email);
sendMessage(email, function (response) {
                //console.log("Handed to Gmail API for sending");
                 {console.log(response)}
            });
            alert("Message sent");
        }

 function sendMessage(email, callback) {
            //auth();
            gapi.client.load('gmail', 'v1',function(){
                var base64EncodedEmail = btoa("MIME-Version: 1.0\n"+
                        "Content-Type:  text/html; charset=\"UTF-8\"\n" +
                    //  "Content-Type:  multipart/mixed; \n" +

                        //"Content-length: 5000\n" +
                        //"Content-Transfer-Encoding: message/rfc822\n"+
                        email).replace(/\//g,'_').replace(/\+/g,'-');
                 // alert("Message sending\n" + base64EncodedEmail.toString());
                console.log(base64EncodedEmail);
                  var request = gapi.client.gmail.users.messages.send({
                    'userId': 'me',
                    'resource': {
                      'raw': base64EncodedEmail
                    }
                  });
                  request.execute(callback);
            });


        }
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
Mohan Gangan
  • 127
  • 11

1 Answers1

1

When you send a Mime email with attachments and inline images, it is contained of many parts.

  • The HTML will be the text/html part.
  • The images will be something like a image/jpeg or image/png part
  • The attachments will be something like a application/pdf part

They are all tied together in a multi-part structure.

The inline images, should be located as siblings to a parent 'multipart/related' mime part. If there are attachments, they are located under a 'multipart/mixed' parent.

If you were to send a mime email with attachments and inlines it would be in the following structure

  • multipart/mixed
    • multipart/related
      • text/html
      • image/jpeg
      • image/jpeg
    • application/pdf

When you call the getData function of the CKEditor, you are only getting the text/html mime part. Within the html is some tags that are referencing an image somewhere. And it will contain absolutely no information about the attachments.

The image can be referenced 3 different ways

  1. As a href to some location of the internet. ie. href="http://someserver.com/someimage.gif" If you are sending emails you probably do not want this unless you are happy with the person receiving the email to have to click 'show images in this email'. And also that you can be sure the image is not a link to some intranet server that is not accessible to the email receiver.

  2. As a Data URI. https://en.wikipedia.org/wiki/Data_URI_scheme This is where all the image data is actually located in the html within the img src tag. The CKEditor will actually allow you (in firefox) to paste in an image in this format, however If you are sending emails you do not want to allow this format either, as it is not supported by every email client. Gmail will not show images in this format.

  3. As an embedded image. This is where the image is stored as a sibling to the text/html in the mime structure as I have described above. The image will have the content-disposition of 'inline' and it will have a Content-ID If you are sending emails this is the format that you really want as you can be sure the receiver will be able to see them.

If you must do everything client side, then you will need to find some way to get the embeddedimage and attachment data from the server to include in your call. Otherwise you are better off trying to do this server-side but in any case you will need to get the server involved somehow.

Cameron Gregor
  • 1,460
  • 7
  • 8
  • I'm using chrome. Sent an email thru gmail to my self and inline images are shown as it is. But when sent from ckeditor to gmail. inline image and files are at proper location but image not displayed as it is and text filename.txt appears. I'm looking for a code to convert ckeditor content to mime which builds the whole structure you mentioned above. – Mohan Gangan Oct 30 '15 at 13:40
  • hi Mohan as I explained above, the ONLY situation where ckeditor can give you the image DATA is if the image is pasted in as a Data URI. even then, gmail will not show it. CKeditor knows where the image location but not content. same thing with attachments. I don't know any other way to explain this to you, CKEditor will only give you the text/html mimepart, so it is impossible to build your whole email using just CKEditor. to get the other parts you would have to make additional request to the server. is there any reason you have to do this all client side ? why not server side? – Cameron Gregor Oct 30 '15 at 20:09
  • Thanks. The domino is application environment and mail environment is gmail. I'm using gmail api to send and it needs authentication with gmail server using client side javascript. That is the reason I'm using CSJS. I used SSJS to save backend notes document and it saves image(sametime emoticons) and simple text file but not displayed properly in notes. It means issue with NotesMimeEntity. That is why I'm looking for client side solution to convert all message in RFC 2822 or 5322 format. That feature is available in node.js but there is less documentation on integration of node.js with xpage – Mohan Gangan Oct 30 '15 at 22:13
  • This is the content in CKeditor. "This is a test. GrinThis is sametime emoticon which is gif. file. test.txtThis is simple .txt file. Both are inline."(can't copy image). The richCKEditor.getData()method shows console log as

    This is a test. GrinThis is sametime emoticon which is gif. file. test.txtThis is simple .txt file. Both are inline.

    which has source.
    – Mohan Gangan Oct 30 '15 at 22:24
  • The NotesMimeEntity creates Mime entity with proper content type definition and for text, image and attachment as shown here: ield Name: MailBody Data Type: MIME Part Data Length: 208 bytes Seq Num: 2 Dup Item ID: 0 Field Flags: SUMMARY "MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==IFJRGLKFGIR29455UHRUHIHD" Content-Type: multipart/mixed; boundary="==IFJRGLKFGIR29455UHRUHIHD" MIME-Version: 1.0 " but do not have file information. While richtextCKeditor has file soruce but it is html format. I need some javascript code to automatically find boundaries. – Mohan Gangan Oct 30 '15 at 22:33
  • and add content type accordingly – Mohan Gangan Oct 30 '15 at 22:33
  • Mohan have a look at the URL in your IMG tag. it falls under category 1. above 'a location somewhere in the internet' it is also a relative URL. when you view this html from domino the image will show because it is on the domino server. when you view this html on gmail ( or any other server) it will not show because it does not specify the path to the domino server (it is not absolute) furthermore that particular image may not show for someone who is not authenticated with the domino environment. I suggest you revisit the problem that stopped you from trying server side as it will be easier – Cameron Gregor Oct 30 '15 at 22:38
  • Mohan you need to take a step back and try and understand my answer, the only data you will get from ckeditor is html. trying to find mime boundary client side is pointless as ckeditor is not doing anything with mime – Cameron Gregor Oct 30 '15 at 22:41
  • I will try to record a video explaining this to you via demonstration. it is a complicated topic. give me 24 hours – Cameron Gregor Oct 30 '15 at 22:44
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93842/discussion-between-mohan-gangan-and-cameron-gregor). – Mohan Gangan Oct 30 '15 at 22:46
  • no prob, it is Saturday here in Australia and I am not at computer, so I will wait until tonight and then try and help a bit more – Cameron Gregor Oct 30 '15 at 22:53
  • Enjoy spring!! I've to wait for another 6 months(; as I'm in NY – Mohan Gangan Nov 01 '15 at 03:40