web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

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 61
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.
I have the same question (0)
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    21,042 Super User 2025 Season 2 on at
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,529 Super User 2025 Season 2 on at
    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.

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,688

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 784 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 595 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans