+ Start a Discussion
Praful GadgePraful Gadge 

Split Long Blob into Multiple Lines for MIME creation

Hi Geeks,

I have created a MIME construction snippet for sending email through Amazon SES.

While sending a large attachment I am getting error "smtp; 500 Line limit exceeded" which means the maximum limit of characters in one line is exceeded and it leads to email bounce/failure. Because the blob of the large attachment is coming in a single line.

I tried splitting the attachment blob in the following way but it is not rendering attachment. I need to split a blob in such a way that the resulting multiline blob is still base64 encoded blob and can render as pdf/text attachment.

Code I have written is as follows:


String strLongBlob = attachmentBlob.toString();

System.debug('---strLongBlob----'+strLongBlob);

String strNewLineBlob = '';

Integer intMaxLineLength = 50;

while( strLongBlob.length() > intMaxLineLength )
{
strNewLineBlob += Encodingutil.base64Encode(blob.valueOf(strLongBlob.left(intMaxLineLength))) + '\r\n';

strLongBlob = strLongBlob.substring(intMaxLineLength);
}

if( strLongBlob.length() <= intMaxLineLength )
strNewLineBlob += Encodingutil.base64Encode(blob.valueOf(strLongBlob));
else
strNewLineBlob += Encodingutil.base64Encode(blob.valueOf(strLongBlob));

System.debug('---strNewLineBlob.length----'+strNewLineBlob.length());


If anyone has worked on this earlier please let me know.

Thanks
Ashish_SFDCAshish_SFDC
Hi Praful, 


Try using the Chunk Split, 

http://stackoverflow.com/questions/11700189/avoiding-500-line-limit-exceeded-error-while-sending-emails

string chunk_split ( string $body [, int $chunklen = 76 [, string $end = "\r\n" ]] )

http://www.php.net/manual/en/function.chunk-split.php


Regards,
Ashish