//attachements
DocAtt.SetRange(/Table ID/, 112);
DocAtt.SetRange(/No./, SIH2Print./No./);
if DocAtt.FindSet() then
repeat
if DocAtt./Document Reference ID/.HasValue then begin
TempBlob.CreateOutStream(DocOutstr);
DocAtt./Document Reference ID/.ExportStream(DocOutstr);
TempBlob.CreateInStream(DocInstream);
FileName := DocAtt./File Name/ + '.' + DocAtt./File Extension/;
case UpperCase(DocAtt./File Extension/) of
'PDF':
ContentType := pdfLabel;
'XLSX':
contentType := excelLabel;//'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
end;
EmailMessage.AddAttachment(FileName, contentType, DocInstream);
end;
until DocAtt.Next() = 0;
sent := Email.Send(EmailMessage);