Example #1
0
        public IActionResult TestEmail()
        {
            var model = new TestSendEmailViewModel();

            model.Subject         = "Testing Email Providers";
            model.ConfigLookupKey = _currentSite.Id.ToString();


            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> TestEmail(TestSendEmailViewModel model)
        {
            var sender = await _emailSenderResolver.GetEmailSender(model.ConfigLookupKey);

            var messageModel = new TestEmailMessageViewModel
            {
                Tenant   = _currentSite,
                Greeting = "Hey there from " + sender.Name,
                Message  = model.Message
            };

            var htmlMessage
                = await _viewRenderer.RenderViewAsString <TestEmailMessageViewModel>("TestEmailMessage", messageModel).ConfigureAwait(false);

            if (model.AttachmentFilePathsCsv == "joetest")
            {
                model.AttachmentFilePathsCsv = @"C:\_c\cloudscribe\src\sourceDev.WebApp\wwwroot\testfiles\PowerShell_Examples_v4.pdf,C:\_c\cloudscribe\src\sourceDev.WebApp\wwwroot\testfiles\Shortcut-Keys-For-Windows-10.docx";
            }

            List <EmailAttachment> attachments = null;

            string[] attachmentPaths = null;
            if (!string.IsNullOrWhiteSpace(model.AttachmentFilePathsCsv))
            {
                attachments     = new List <EmailAttachment>();
                attachmentPaths = model.AttachmentFilePathsCsv.Split(',');
                foreach (var path in attachmentPaths)
                {
                    var stream     = System.IO.File.OpenRead(path);
                    var attachment = new EmailAttachment(stream, Path.GetFileName(path));
                    attachments.Add(attachment);
                }
            }

            var result = await sender.SendEmailAsync(
                model.ToEmailCsv,
                model.FromEmail,
                model.Subject,
                null,
                htmlMessage,
                replyToEmail : model.ReplyToEmail,
                replyToName : model.ReplyToName,
                fromName : model.FromName,
                toAliasCsv : model.ToAliasCsv,
                ccEmailCsv : model.CcEmailCsv,
                ccAliasCsv : model.CcAliasCsv,
                bccEmailCsv : model.BccEmailCsv,
                bccAliasCsv : model.BccAliasCsv,
                attachments : attachments,
                configLookupKey : model.ConfigLookupKey


                ).ConfigureAwait(false);

            if (result.Succeeded)
            {
                this.AlertSuccess("message sent", true);
            }
            else
            {
                this.AlertDanger(result.ErrorMessage, true);
            }


            return(RedirectToAction("TestEmail"));
        }