Skip to main content

Notifications

Business Central forum
Suggested answer

Sending Excel as Attached File Corrupts the file

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!
  • CU21050032-0 Profile Picture
    CU21050032-0 4 on at
    Sending Excel as Attached File Corrupts the file
    After countless hours searching, I found a software solution that truly stands out. The quality and efficiency of their work is simply stunning. What sets them apart is their ability to create custom solutions for a variety of sectors. I was particularly impressed with the intuitive user interfaces and solid back-end structures. Clearly, the team at PNN Soft is truly committed to their craft. If you're in the market for top-tier software solutions, I can't recommend a better option. Do yourself a favor and visit this site.
  • Sending Excel as Attached File Corrupts the file
    Life is constantly providing us with opportunities to learn and experience new things, and finding https://savetiktok.org is a great example of this. I knew about Tiktok, but I thought that the videos could only be viewed in the app itself and only with an internet connection. It turns out that thanks to this site, you can easily download any video from Tiktok and enjoy it anytime and anywhere. 
  • Community member Profile Picture
    Community member 18 on at
    Sending Excel as Attached File Corrupts the file
    Hmm, it's very difficult to understand what's written here. It might be better to consult a specialist to help understand or install it where it needs to go. But of course, that requires money. For instance, I receive a small portion of my funds from the website https://www.newukcasino.uk/casino-minimum-deposit/ . They offer a good deposit and teach you how to play properly to avoid being a loser.
  • Suggested answer
    Kamal Khakhkhar Profile Picture
    Kamal Khakhkhar 231 on at
    Sending Excel as Attached File Corrupts the file
    hii there,
    As per your question i suggest to make function for clear code. and you can separate the function for create excel, save excel, send file, if you tying all in single part it will be make you hard to understand. here i attached a link to create and send excel file to email. go through it.
     
     
    If you found useful mark it answered.
     
    Thank You.
    Kamal Khakhkhar

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,246 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,041 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans