28 September 2023

4 thoughts on “Business Central Send Email with Multi Attachments

  1. Roberto,

    Do you happen to know how to overwrite SMTP settings to use a different server/user to:
    1. Allows BC users to send emails as themselves, and
    2. To allow jobs to send emails as Customer Service, or Billing accounts
    To allow this to happen, we need two different SMTP configurations.

    Thank you,

  2. Wіth havin ѕo muⅽh сontent ɗo you ever run into any issues of plagorism oг
    copyright violation? Ⅿy site һas a loot οf unique content I’ѵe eіther cгeated myself or outsokurced but it
    ѕeems a lot of it is popping it uр aⅼl oveг the internet withput mʏ agreement.
    Ɗо yoս kniw ɑny methods to helρ ѕtop content from Ƅeing stolen?
    І’d truly apрreciate it.

  3. Updated Code:

    PROCEDURE ReportSendMailWithExternalAttachment(
    ReportToSend: Integer;
    Recordr: RecordRef;
    TableID: Integer;
    DocNo: Text;
    ToAddr: List of [Text];
    Subject: Text[100];
    Body: Text[200];
    AttachmentName: Text[100];
    Param: Text; var Purchaseheader: Record “Purchase Header”): Boolean
    var
    TempBlob: Codeunit “Temp Blob”;
    outStreamReport: OutStream;
    inStreamReport: InStream;
    TempBlobAtc: Array[10] of Codeunit “Temp Blob”;
    outStreamReportAtc: Array[10] of OutStream;
    inStreamReportAtc: Array[10] of InStream;
    Parameters: Text;
    EmailObj: Codeunit Email;
    EmailMsg: Codeunit “Email Message”;
    Question: Label ‘Are you Sure you want to send an email to %1’;
    SendYesNo: Boolean;
    // Attachments
    FullFileName: Text;
    DocumentAttachment: record “Document Attachment”;
    i: Integer;

    begin
    EmailMsg.Create(ToAddr, Subject, Body, false);
    //Generate blob from report
    TempBlob.CreateOutStream(outStreamReport);
    TempBlob.CreateInStream(inStreamReport);
    Report.SaveAs(ReportToSend, Param, ReportFormat::Pdf, outStreamReport, Recordr);
    // Mail.AddAttachmentStream(inStreamReport, AttachmentName);
    i := 1;

    //Get attachment from the document – streams
    DocumentAttachment.Reset();
    DocumentAttachment.setrange(“Table ID”, TableID);
    DocumentAttachment.setrange(“No.”, DocNo);
    if DocumentAttachment.FindSet() then begin
    repeat
    if DocumentAttachment.”Document Reference ID”.HasValue then begin
    TempBlobAtc[i].CreateOutStream(outStreamReportAtc[i]);
    TempBlobAtc[i].CreateInStream(inStreamReportAtc[i]);
    FullFileName := DocumentAttachment.”File Name” + ‘.’ + DocumentAttachment.”File Extension”;
    if DocumentAttachment.”Document Reference ID”.ExportStream(outStreamReportAtc[i]) then begin
    //Mail Attachments
    EmailMsg.AddAttachment(FullFileName, ‘PDF,’, inStreamReportAtc[i]);
    end;
    i += 1;
    end;
    until DocumentAttachment.NEXT = 0;
    end;

    //Send mail
    exit(EmailObj.Send(EmailMsg));
    end;

Comments are closed.