public static void SendApprovalRequestEmail(
            [ActivityTrigger] ApprovalInfo approvalInfo,
            [SendGrid(ApiKey = "SendGridKey")] out SendGridMessage message,
            [Table("Approvals", Connection = "AzureWebJobsStorage")] out Approval approval,
            ILogger log)
        {
            string approvalCode = Guid.NewGuid().ToString("N");

            approval = new Approval
            {
                PartitionKey    = "Approval",
                RowKey          = approvalCode,
                OrchestrationId = approvalInfo.OrchestrationId
            };

            string host = Environment.GetEnvironmentVariable("Host");

            // constructs the email attributes
            string functionAddress = $"{host}/api/SubmitVideoApproval/{approvalCode}";
            string approvedLink    = functionAddress + "?result=Approved";
            string rejectedLink    = functionAddress + "?result=Rejected";
            string emailBody       =
                $"Please review {approvalInfo.VideoLocation}<br>"
                + $"<a href=\"{approvedLink}\">Approve</a><br>"
                + $"<a href=\"{rejectedLink}\">Reject</a>";

            // appends attributes to email, sends with sendgrid api
            message = new SendGridMessage();
            message.AddTo(Environment.GetEnvironmentVariable("ApproverEmail"));
            message.AddContent("text/html", emailBody);
            message.SetFrom(new EmailAddress(Environment.GetEnvironmentVariable("SenderEmail")));
            message.SetSubject("Approve this message");
        }
Пример #2
0
        public static void SendApprovalRequestEmail(
            [ActivityTrigger] ApprovalInfo approvalInfo,
            [SendGrid(ApiKey = "SendGridKey")] out Mail message,
            [Table("Approvals", "AzureWebJobsStorage")] out Approval approval,
            TraceWriter log)
        {
            var approvalCode = Guid.NewGuid().ToString("N");

            approval = new Approval
            {
                PartitionKey    = "Approval",
                RowKey          = approvalCode,
                OrchestrationId = approvalInfo.OrchestrationId
            };

            var approverEmail   = new Email(ConfigurationManager.AppSettings["ApproverEmail"]);
            var senderEmail     = new Email(ConfigurationManager.AppSettings["SenderEmail"]);
            var subject         = "A video is awaiting approval";
            var host            = ConfigurationManager.AppSettings["Host"];
            var functionAddress = $"{host}/api/SubmitVideoApproval/{approvalCode}";
            var approvedLink    = functionAddress + "?result=Approved";
            var rejectedLink    = functionAddress + "?result=Rejected";
            var body            = $"Please review {approvalInfo.VideoLocation}<br>"
                                  + $"<a href=\"{approvedLink}\">Approve</a><br>"
                                  + $"<a href=\"{rejectedLink}\">reject</a><br>";
            var content = new Content("text/html", body);

            message = new Mail(senderEmail, subject, approverEmail, content);
        }
        public static void SendApprovalRequestEmail(
            [ActivityTrigger] ApprovalInfo approvalInfo,
            [SendGrid(ApiKey = "SendGridKey")] out SendGridMessage message,
            [Table("Approvals", "AzureWebJobsStorage")] out Approval approval,
            ILogger log)
        {
            var approvalCode = Guid.NewGuid().ToString("N");

            approval = new Approval
            {
                PartitionKey    = "Approval",
                RowKey          = approvalCode,
                OrchestrationId = approvalInfo.OrchestrationId
            };
            var approverEmail = new EmailAddress(Environment.GetEnvironmentVariable("ApproverEmail"));
            var senderEmail   = new EmailAddress(Environment.GetEnvironmentVariable("SenderEmail"));

            log.LogInformation($"Sending approval request for {approvalInfo.VideoLocation}");
            var host = Environment.GetEnvironmentVariable("Host");

            var functionAddress = $"{host}/api/SubmitVideoApproval/{approvalCode}";
            var approvedLink    = functionAddress + "?result=Approved";
            var rejectedLink    = functionAddress + "?result=Rejected";
            var body            = $"Please review {approvalInfo.VideoLocation}<br>"
                                  + $"<a href=\"{approvedLink}\">Approve</a><br>"
                                  + $"<a href=\"{rejectedLink}\">Reject</a>";

            message         = new SendGridMessage();
            message.Subject = "A video is awaiting approval (V2)";
            message.From    = senderEmail;
            message.AddTo(approverEmail);
            message.HtmlContent = body;
            log.LogWarning(body);
        }