in src/backend/SendNotificationTask/Function.cs [68:120]
private async Task SendEmail(Exam nextExam, string studentId, string token, string incidentId, int examCount)
{
try
{
var client = new SendGridClient(_apiKey);
var from = new EmailAddress(_fromEmail, "AWS Step Functions Plagiarism Demo Administrator");
var subject = $"AWS Step Functions Plagiarism Demo Exam Notification for {studentId}";
var to = new EmailAddress(_toEmail);
var plainTextContent =
$"Dear Student (ID: {studentId})," +
$"\n" +
"You have been suspected of plagiarism. You must pass an exam, or you will be referred for administrative action." +
"\n" +
$"You have until {nextExam.ExamDeadline} to complete your Plagiarism Violation exam." +
"\n" +
$"This is your {examCount} of 3 attempts. The passmark is 70%." +
"\n" +
"Thank you." +
"\n" +
"Please copy and paste this link into your browser to start your exam." +
"\n" +
$"{_testingCentreUrl}?TaskToken={token}&ExamId={nextExam.ExamId}&IncidentId={incidentId}";
var htmlContent =
$"<p>Dear Student (ID: {studentId}),</p>" +
"<p>You have been suspected of plagiarism. You must pass an exam, or you will be referred for administrative action.</p>" +
$"<p>You have until <strong>{nextExam.ExamDeadline}</strong> to complete your Plagiarism Violation exam.</p> " +
$"<p>This is your <strong>{examCount} of 3</strong> attempts. The passmark is 70%.</p>" +
"<p>Thank you.</p>" +
$"<p><a href=\"{_testingCentreUrl}?TaskToken={token}&ExamId={nextExam.ExamId}&IncidentId={incidentId}\"><strong>Click here to start your exam</strong></a></p>" +
$"<p>If the URL does not work, copy and paste this into the address bar of your browser <br/> {_testingCentreUrl}?TaskToken={token}&ExamId={nextExam.ExamId}&IncidentId={incidentId}</p>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
Console.WriteLine(msg.Serialize());
AWSXRayRecorder.Instance.BeginSubsegment("Sendgrid", DateTime.Now);
var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
AWSXRayRecorder.Instance.EndSubsegment();
Console.WriteLine(response.StatusCode);
if (response.StatusCode == HttpStatusCode.Accepted)
{
nextExam.NotificationSent = true;
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}