Skip to main content
Suggested answer

Sending Excel as Attached File Corrupts the file

editSubscribe (1) ShareShare
ReportReport
Posted on by 2
Hi everyone!
 
I am sending document attachment files with Sales Invoices as PDFs via e-mail.
If the attached files are PDFs everything works fine, but if the file is an EXCEL, the reciever gets that file corrupted.

The code is pretty simple and straightforward, have you seen/experienced anything similar?
//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);
Any help is apreciated.
 
Thanks!