+ Start a Discussion
sf consultant.ax380sf consultant.ax380 

Sending Email via Java / Web Services API with Images embedded as Attachments? How can it be done?

Hello all,

We have users that create html documents on the fly in our application.. some may include images.. these images our stored in our DB as blobs.. Currently we use the javax.mail classes but want to switch to the SF Web Services API to send the email. 

In our current version of our 3rd party application,  HTML Images are included as attachments to the email as opposed to absolute URL's as they are stored as blobs in the database and do not exist on any file system. The HTML references the images using the protocol prefix cid: and the content id of the attachment.

I’m looking at the SF web services API and trying to find something I can use to duplicate this.  I see the setFileAttachments and setDocumentAttachments methods but I’m thinking these are not what I want to use?

Any ideas are appreciated!!!

The below is more pseudo then actual code but you should get the idea.

-------Using the javax.mail classes........
messageBodyPart = new MimeBodyPart();
DataSource fds = new FileDataSource("C:\\images\\jht.gif");
messageBodyPart.setDataHandler(new DataHandler(fds));

---------in the SF web service API...
com.sforce.soap.enterprise.SingleEmailMessage email =              new SingleEmailMessage()
email.setFileAttachments(i, _value)
email.setDocumentAttachments(i, _value)


Message Edited by sf consultant on 09-09-2008 12:03 PM
Ron HessRon Hess
i think

will do that
sf consultant.ax380sf consultant.ax380
Thank you so much for your response Ron.

Isn't a Document an actual salesforce object?  I'm thinking in terms of each email may have 1-n images.. (The emails are created in a 3rd party application and we are not really sure of the the volume of images as the publisher is creating these html documents stored in the 3rd party app) .  We really do not want to actually store these images on the SF server as there is really no need to store them plus it would be additional coding. hmm.. I'll have to think more.

I actual tried the FileAttachment and our images were attached but appeared to the user more like say word attachments then images in the html source.

And btw.. what is the true difference in SF terms of a Document Attachments versus a File Attachment?

Thank you so much.

Really  are looking to replace something like
         messageBodyPart.setHeader("Content-ID", "<"+attachedBlob.getUUID().replace('-','.')+"@domain.com>");
         messageBodyPart.setHeader("Content-Type", attachedBlob.getMimeType());
        // messageBodyPart.setDisposition(Part.INLINE);
         messageBodyPart.setDataHandler(new DataHandler(new BlobDataSource(attachedBlob)));
 strBuffer.insert(nOffset, "cid:"+ ((APIDocument.Blob) attachedBlobList.get(blobOffset[i])).getUUID().replace('-','.') +"@domain.com");