Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Sending Mail Using Job Queue

(3) ShareShare
ReportReport
Posted on by 57
I have to send a email in Bulk  using Job Queue and in Email I have attached then ICS Calendar File and Body I have attached word layout report . Now for that I am giving one scenario for that 
 
 
I have one Table Interview_master in these there are Multiple records and its record Consists candidate details and Interviewer Details and in these I want to send a mail to Candidate and Interviewer Whose Record Status is Released in that Candidate email are same , interviewer Email are different , interview time,date and location are different as shown in Image  for that I have make one codeunit that Run in Job Queue 
 
codeunit 50101 "Job Queue"
{
    trigger OnRun()
    var
        interviewrec: Record Interview_Master;
    begin
 
        interviewRec.Reset();
 
        interviewrec.SetRange(Status, interviewrec.Status::Release);
        if interviewRec.FindSet() then begin
            repeat
                SendEmail(interviewRec);
                interviewrec.send_email := true;
                interviewrec.Modify();
            until interviewRec.Next() = 0;
        end;
 
    end;
 
    local procedure SendEmail(interviewrec: Record Interview_Master)
    var
        candidaterec: Record Candidate_Master;
        email: Codeunit "Email";
        emailMsg: Codeunit "Email Message";
        tempBlob: Codeunit "Temp Blob";
        inStr: InStream;
        outStr: OutStream;
        recRef: RecordRef;
        htmlContent: Text;
        candidateEmail: Text;
        icsContent: Text;
        icsStream: OutStream;
        icsInStream: InStream;
        icsBlob: Codeunit "Temp Blob";
        ics: Codeunit "ICS EXT";
 
        //interviewre Variables
        interviewerEmail: Text;
        interviewerICSBlob: Codeunit "Temp Blob";
        interviewerHTMLBlob: Codeunit "Temp Blob";
        icsInterviewerContent: Text;
        icsOutStream: OutStream;
        icsInStream2: InStream;
        interviewerHtml: Text;
        recRefInterviewer: RecordRef;
        emailMsgInterviewer: Codeunit "Email Message";
        emailInterviewer: Codeunit "Email";
    begin
        if not candidateRec.Get(interviewRec.candidate_code) then
            exit;
 
        candidateEmail := interviewRec.candidate_email;
        if candidateEmail <> '' then begin
            icsContent := ics.GetCalendarICSContent(
                interviewRec.interview_date,
                interviewRec.interview_time,
                interviewRec.interviewer_name,
                interviewRec.interview_location,
                candidateEmail,
                candidateRec.candidate_name);
 
            if icsContent <> '' then begin
                icsBlob.CreateOutStream(icsStream);
                icsStream.WriteText(icsContent);
                icsBlob.CreateInStream(icsInStream);
 
                recRef.GetTable(interviewRec);
                Clear(outStr);
                tempBlob.CreateOutStream(outStr);
                Report.SaveAs(Report::"Interview Report", '', ReportFormat::Html, outStr, recRef);
 
                 Clear(inStr);
                tempBlob.CreateInStream(inStr);
                inStr.ReadText(htmlContent);
 
                emailMsg.Create(candidateEmail, 'Candidate Interview Invitation', htmlContent, true);
                emailMsg.AddAttachment('Candidate Interview Invitation.ics', 'text/calendar', icsInStream);
                email.Send(emailMsg, Enum::"Email Scenario"::Default);
            end;
        end;
 
        interviewerEmail := interviewRec.interview_email;
        if interviewerEmail <> '' then begin
            icsInterviewerContent := ics.GetCalendarICSContentInterviewer(
                interviewRec.interview_date,
                interviewRec.interview_time,
                interviewRec.interviewer_name,
                interviewRec.interview_location,
                candidateEmail,
                candidateRec.candidate_name,
                interviewerEmail);
 
            if icsInterviewerContent <> '' then begin
                interviewerICSBlob.CreateOutStream(icsOutStream);
                icsOutStream.WriteText(icsInterviewerContent);
                interviewerICSBlob.CreateInStream(icsInStream2);
 
                recRefInterviewer.GetTable(interviewRec);
                Clear(outStr);
                interviewerHTMLBlob.CreateOutStream(outStr);
                Report.SaveAs(Report::"Interviewer Report", '', ReportFormat::Html, outStr, recRefInterviewer);
 
                Clear(inStr);
                interviewerHTMLBlob.CreateInStream(inStr);
                inStr.ReadText(interviewerHtml);
 
                emailMsgInterviewer.Create(interviewerEmail, 'Interview Schedule', interviewerHtml, true);
                emailMsgInterviewer.AddAttachment('Schedule.ics', 'text/calendar', icsInStream2);
                emailInterviewer.Send(emailMsgInterviewer, Enum::"Email Scenario"::Default);
            end;
        end;


 
    end;



 
}

But the Problem is that mail counts are not properly if 5 records are released then only 5 mails are go to the candidate email and one -one for each different interviewer email and also data is not Properly Populated in Interview Date,Time,Location and Interview Round so for that I have attached also report.
  • Suggested answer
    Ramesh Kumar Profile Picture
    4,514 on at
    Sending Mail Using Job Queue
    Hi,
     
    I hope the information below helps. I need to properly test this to ensure all exceptions are handled and performance is optimal.
     
     
    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    16,572 Super User 2025 Season 1 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 1,200

#2
YUN ZHU Profile Picture

YUN ZHU 1,006 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 864

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans