예제 #1
0
        public void Setup()
        {
            _smtpTestAccount           = new SmtpAccount();
            _smtpTestAccount.AccountId = "SmtpTestAccountId";

            _profile = new ConversionProfile();
            //Attention
            _profile.EmailSmtpSettings.AccountId = _smtpTestAccount.AccountId;
            //The AccountAssosiation is mocked below. The _smtpTestAccount is always used.

            _accounts = new Accounts();
            _accounts.SmtpAccounts.Add(_smtpTestAccount);

            _interactionRequest = new UnitTestInteractionRequest();
            _interactionInvoker = Substitute.For <IInteractionInvoker>();
            _interactionInvoker.Invoke(Arg.Do <PasswordOverlayInteraction>(i => i.Result = PasswordResult.StorePassword));

            _interactionRequest.RegisterInteractionHandler <PasswordOverlayInteraction>(interaction => interaction.Result = PasswordResult.StorePassword);

            _file       = Substitute.For <IFile>();
            _path       = Substitute.For <IPath>();
            _smtpAction = Substitute.For <ISmtpMailAction>();
            _smtpAction.Check(Arg.Any <ConversionProfile>(), _accounts, Arg.Any <CheckLevel>()).Returns(x => new ActionResult());
            _smtpAction.ProcessJob(Arg.Any <Job>()).Returns(x => new ActionResult());
            //_smtpAction.GetSmtpAccount(_profile, _accounts).Returns(_smtpTestAccount);

            _mailSignatureHelper = Substitute.For <IMailSignatureHelper>();
            _mailSignatureHelper.ComposeMailSignature().Returns(_mailSignature);

            _tokenReplacer        = new TokenReplacer();
            _tokenReplacerFactory = Substitute.For <ITokenReplacerFactory>();
            _tokenReplacerFactory.BuildTokenReplacerWithOutputfiles(Arg.Any <Job>()).Returns(_tokenReplacer);

            _translation = new SmtpTranslation();
        }
        public override void Execute(object obj)
        {
            List <string> files     = GetPaths(obj);
            var           signature = _mailSignatureHelper.ComposeMailSignature();

            _action.OpenEmptyClient(files, signature);
        }
예제 #3
0
        public override void Execute(object obj)
        {
            List <string> files     = GetPaths(obj);
            var           signature = _mailSignatureHelper.ComposeMailSignature();

            _action.Process("", "", false, true, signature, "", "", "", true, files);
        }
예제 #4
0
        public EditEmailTextViewModel(ITranslationUpdater translationUpdater, IMailSignatureHelper mailSignatureHelper, ITokenHelper tokenHelper, TokenViewModelFactory tokenViewModelFactory)
            : base(translationUpdater)
        {
            _tokenReplacer = tokenHelper.TokenReplacerWithPlaceHolders;

            var builder = tokenViewModelFactory
                          .Builder <EditEmailTextInteraction>()
                          .WithInitialValue(Interaction)
                          .WithTokenList(tokenHelper.GetTokenListForEmail());

            SubjectTokenViewModel = builder
                                    .WithSelector(i => i.Subject)
                                    .WithDefaultTokenReplacerPreview()
                                    .Build();

            ContentTokenViewModel = builder
                                    .WithSelector(i => i.Content)
                                    .WithTokenCustomPreview(ReplaceTokensAddSignature)
                                    .Build();

            _signatureText = mailSignatureHelper.ComposeMailSignature();

            OkCommand     = new DelegateCommand(ExecuteOk);
            CancelCommand = new DelegateCommand(o => FinishInteraction());
        }
예제 #5
0
        public void Setup()
        {
            _profile = new ConversionProfile();

            _interactions       = new List <IInteraction>();
            _interactionInvoker = Substitute.For <IInteractionInvoker>();

            _interactionInvoker
            .When(x => x.Invoke(Arg.Any <PasswordInteraction>()))
            .Do(x =>
            {
                var interaction    = x.Arg <PasswordInteraction>();
                interaction.Result = PasswordResult.StorePassword;
            });

            _interactionInvoker
            .When(x => x.Invoke(Arg.Any <IInteraction>()))
            .Do(x =>
            {
                _interactions.Add(x.Arg <IInteraction>());
            });

            _file       = Substitute.For <IFile>();
            _path       = Substitute.For <IPath>();
            _smtpAction = Substitute.For <ISmtpMailAction>();
            _smtpAction.Check(_profile, Arg.Any <Accounts>()).Returns(x => new ActionResult());
            _smtpAction.ProcessJob(Arg.Any <Job>()).Returns(x => new ActionResult());

            _mailSignatureHelper = Substitute.For <IMailSignatureHelper>();
            _mailSignatureHelper.ComposeMailSignature().Returns(_mailSignature);
        }
예제 #6
0
        public void SetUp()
        {
            _smtpTestAccount           = new SmtpAccount();
            _smtpTestAccount.AccountId = "TestAccountId";
            _smtpTestAccount.Address   = "*****@*****.**";
            _smtpTestAccount.UserName  = "******";
            _smtpTestAccount.Server    = "randomHost";
            _smtpTestAccount.Port      = 25;
            _smtpTestAccount.Ssl       = false;
            _smtpTestAccount.Password  = "******";

            _profile = new ConversionProfile();
            _profile.EmailSmtpSettings.Enabled      = true;
            _profile.EmailSmtpSettings.AccountId    = _smtpTestAccount.AccountId;
            _profile.EmailSmtpSettings.Recipients   = "*****@*****.**";
            _profile.EmailSmtpSettings.Subject      = "";
            _profile.EmailSmtpSettings.Content      = "";
            _profile.EmailSmtpSettings.AddSignature = false;

            _accounts = new Accounts();
            _accounts.SmtpAccounts.Add(_smtpTestAccount);

            _mailSignatureHelper = Substitute.For <IMailSignatureHelper>();
            _mailSignatureHelper.ComposeMailSignature().Returns("Signature!");

            _smtpAction = new SmtpMailAction(_mailSignatureHelper);
        }
예제 #7
0
        public void SetUp()
        {
            var fixture = new Fixture();

            _userName     = fixture.Create <string>();
            _smtpPassword = fixture.Create <string>();

            _mailSignatureHelper = Substitute.For <IMailSignatureHelper>();
            _mailSignatureHelper.ComposeMailSignature().Returns("");

            var bootstrapper = new IntegrationTestBootstrapper();
            var container    = bootstrapper.ConfigureContainer();

            _th = container.GetInstance <TestHelper>();
            _th.InitTempFolder("SmtpEmailTest");

            _tokenReplacer = new TokenReplacer();
            _tokenReplacer.AddStringToken("ReplaceThis", "Replaced");

            var serverIp = IPAddress.Loopback;

            _smtpPort   = FindFreeTcpPort();
            _mailServer = serverIp.ToString();
            _smtpServer = new SmtpServerForUnitTest(serverIp, _smtpPort, new[] { new NetworkCredential(_userName, _smtpPassword) });
            _smtpServer.Start();
        }
예제 #8
0
        public bool SendTestEmail(EmailClientSettings clientSettings)
        {
            var emailClient = _emailClientFactory.CreateEmailClient();

            if (emailClient == null)
            {
                return(false);
            }

            var eMail         = new Email();
            var tokenReplacer = _tokenHelper.TokenReplacerWithPlaceHolders;

            clientSettings.Recipients = tokenReplacer.ReplaceTokens(clientSettings.Recipients);
            foreach (var recipient in clientSettings.Recipients.Replace(',', ';').Split(';'))
            {
                if (!string.IsNullOrWhiteSpace(recipient))
                {
                    eMail.To.Add(recipient.Trim());
                }
            }

            eMail.Subject = tokenReplacer.ReplaceTokens(clientSettings.Subject);
            eMail.Html    = clientSettings.Html;
            eMail.Body    = tokenReplacer.ReplaceTokens(clientSettings.Content);

            if (clientSettings.AddSignature)
            {
                var signature = _mailSignatureHelper.ComposeMailSignature();
                if (clientSettings.Html)
                {
                    signature = signature.Replace(Environment.NewLine, "<br/>");
                }
                eMail.Body += signature;
            }

            try
            {
                var tempFolder    = _path.GetTempPath();
                var tmpTestFolder = _pathSafe.Combine(tempFolder, "PDFCreator-Test\\SendSmtpTestmail");
                _directory.CreateDirectory(tmpTestFolder);
                var tmpFile = _pathSafe.Combine(tmpTestFolder, "PDFCreator Mail Client Test.pdf");
                _file.WriteAllText(tmpFile, "");
                eMail.Attachments.Add(new Attachment(tmpFile));

                emailClient.ShowEmailClient(eMail);
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, "Exception while creating mail");
                return(false);
            }
            return(true);
        }
        public EditEmailTextViewModel(ITranslationUpdater translationUpdater, IMailSignatureHelper mailSignatureHelper, TokenHelper tokenHelper)
            : base(translationUpdater)
        {
            if (tokenHelper != null)
            {
                _tokenReplacer = tokenHelper.TokenReplacerWithPlaceHolders;

                SubjectTokenViewModel = new TokenViewModel(x => Interaction.Subject = x, () => Interaction?.Subject, tokenHelper.GetTokenListForEmail(), ReplaceTokens);
                ContentTokenViewModel = new TokenViewModel(x => Interaction.Content = x, () => Interaction?.Content, tokenHelper.GetTokenListForEmail(), ReplaceTokensAddSignature);
            }

            _signatureText = mailSignatureHelper.ComposeMailSignature();

            OkCommand     = new DelegateCommand(ExecuteOk);
            CancelCommand = new DelegateCommand(o => FinishInteraction());
        }
예제 #10
0
        public void SendTestMail_SignatureGetsAttachedToContent()
        {
            _emailClientSettings.Content = "content";
            var currentEmail = new Email();

            _emailClient.When(x => x.ShowEmailClient(Arg.Any <Email>())).Do(
                x =>
            {
                currentEmail = x[0] as Email;
            });
            _mailSignatureHelper.ComposeMailSignature(_emailClientSettings).Returns("Signature");

            _clientTestEmail.SendTestEmail(_emailClientSettings);

            _mailSignatureHelper.Received().ComposeMailSignature(_emailClientSettings);
            Assert.AreEqual("contentSignature", currentEmail.Body, "Wrong mail body");
        }
예제 #11
0
        private string BuildBody(IMailActionSettings mailSettings)
        {
            var body = mailSettings.Content;

            if (mailSettings.AddSignature)
            {
                var signature = _mailSignatureHelper.ComposeMailSignature();
                if (mailSettings.Html)
                {
                    signature = signature.Replace(Environment.NewLine, "<br>");
                }

                body += signature;
            }

            return(body);
        }
예제 #12
0
        public Job BuildJobFromJobInfo(JobInfo jobInfo, PdfCreatorSettings settings)
        {
            _logger.Trace("Building Job from JobInfo");

            var preselectedProfile = PreselectedProfile(jobInfo, settings).Copy();

            _logger.Debug("Profile: {0} (GUID {1})", preselectedProfile.Name, preselectedProfile.Guid);

            var jobTranslations = new JobTranslations {
                EmailSignature = _mailSignatureHelper.ComposeMailSignature()
            };

            var job = new Job(jobInfo, preselectedProfile, jobTranslations, settings.ApplicationSettings.Accounts);

            SkipPrintDialog(job);

            return(job);
        }
예제 #13
0
        public EditEmailTextViewModel(EditEmailTextWindowTranslation translation, IMailSignatureHelper mailSignatureHelper, TokenHelper tokenHelper)
        {
            Translation   = translation;
            TokenReplacer = tokenHelper.TokenReplacerWithPlaceHolders;
            var tokens = tokenHelper.GetTokenListForEmail();

            _signatureText = mailSignatureHelper.ComposeMailSignature();

            SubjectTextViewModel         = new TokenViewModel(
                s => Interaction.Subject = s,
                () => Interaction?.Subject,
                tokens);

            BodyTextViewModel            = new TokenViewModel(
                s => Interaction.Content = s,
                () => Interaction?.Content,
                tokens);

            OkCommand = new DelegateCommand(ExecuteOk);
        }
예제 #14
0
        public void Setup()
        {
            _profile = new ConversionProfile();

            _job = new Job(null, null, null)
            {
                Profile     = _profile,
                OutputFiles = new List <string> {
                    "FirstFile.pdf"
                }
            };

            _fileList = new List <string>();
            _fileList.Add("abc");
            _fileList.Add("def");
            _fileList.Add("ghi");

            _emailClientAction   = Substitute.For <IEMailClientAction>();
            _mailSignatureHelper = Substitute.For <IMailSignatureHelper>();
            _mailSignatureHelper.ComposeMailSignature().Returns(SignatureText);
        }
예제 #15
0
        public Job BuildJobFromJobInfo(JobInfo jobInfo, PdfCreatorSettings settings)
        {
            _logger.Trace("Building Job from JobInfo");

            var preselectedProfile = PreselectedProfile(jobInfo, settings).Copy();

            _logger.Debug("Profile: {0} (GUID {1})", preselectedProfile.Name, preselectedProfile.Guid);

            var jobTranslations = new JobTranslations {
                EmailSignature = _mailSignatureHelper.ComposeMailSignature()
            };

            var job = new Job(jobInfo, preselectedProfile, jobTranslations, settings.ApplicationSettings.Accounts);

            if (!job.Profile.AutoSave.Enabled) // TODO this should be set somewhere else
            {
                job.OnJobCompleted += _jobFinishedHandler.OnJobFinished;
            }

            return(job);
        }
예제 #16
0
        public void SendTestMail(ConversionProfile profile, Accounts accounts)
        {
            var currentProfile = profile.Copy();

            currentProfile.AutoSave.Enabled = false;

            var actionResult = _smtpMailAction.Check(currentProfile, accounts);

            if (!actionResult.IsSuccess)
            {
                DisplayErrorMessage(actionResult);
                return;
            }

            var jobTranslations = new JobTranslations();

            jobTranslations.EmailSignature = _mailSignatureHelper.ComposeMailSignature();

            var job = CreateJob(jobTranslations, currentProfile, accounts);

            var success = TrySetJobPasswords(job, profile);

            if (!success)
            {
                return;
            }

            var testFile = _path.Combine(_path.GetTempPath(), _translation.AttachmentFile + ".pdf");

            _file.WriteAllText(testFile, @"PDFCreator", Encoding.GetEncoding("Unicode"));
            job.OutputFiles.Add(testFile);

            var recipients = currentProfile.EmailSmtpSettings.Recipients;

            actionResult = _smtpMailAction.ProcessJob(job);

            _file.Delete(testFile);
            DisplayResult(actionResult, recipients);
        }
예제 #17
0
        public void SendTestMail(ConversionProfile profile, Accounts accounts)
        {
            var currentProfile = profile.Copy();

            currentProfile.AutoSave.Enabled = false;

            var jobTranslations = new JobTranslations();

            jobTranslations.EmailSignature = _mailSignatureHelper.ComposeMailSignature();

            var job = CreateJob(jobTranslations, currentProfile, accounts);

            _smtpMailAction.ApplyPreSpecifiedTokens(job);
            var result = _smtpMailAction.Check(job.Profile, job.Accounts, CheckLevel.Job);

            if (!result)
            {
                DisplayResult(result, job);
                return;
            }

            if (!TrySetJobPasswords(job, profile))
            {
                return;
            }

            var testFile = _path.Combine(_path.GetTempPath(), _translation.AttachmentFile + ".pdf");

            _file.WriteAllText(testFile, @"PDFCreator", Encoding.GetEncoding("Unicode"));
            job.OutputFiles.Add(testFile);

            result = _smtpMailAction.ProcessJob(job);
            DisplayResult(result, job);

            _file.Delete(testFile);
        }
예제 #18
0
        public ActionResult ProcessJob(Job job)
        {
            _logger.Info("Launched client e-mail action");

            var subject      = job.TokenReplacer.ReplaceTokens(job.Profile.EmailClientSettings.Subject);
            var body         = job.TokenReplacer.ReplaceTokens(job.Profile.EmailClientSettings.Content);
            var isHtml       = job.Profile.EmailClientSettings.Html;
            var hasSignature = job.Profile.EmailClientSettings.AddSignature;
            var signature    = string.Empty;

            if (hasSignature)
            {
                signature = _mailSignatureHelper.ComposeMailSignature();
            }

            var recipientsTo  = job.TokenReplacer.ReplaceTokens(job.Profile.EmailClientSettings.Recipients).Replace(';', ',');
            var recipientsCc  = job.TokenReplacer.ReplaceTokens(job.Profile.EmailClientSettings.RecipientsCc).Replace(';', ',');
            var recipientsBcc = job.TokenReplacer.ReplaceTokens(job.Profile.EmailClientSettings.RecipientsBcc).Replace(';', ',');

            var            hasAttachments = !SkipFileAttachments(job);
            IList <string> attachments    = hasAttachments ? job.OutputFiles : null;

            return(Process(subject, body, isHtml, hasSignature, signature, recipientsTo, recipientsCc, recipientsBcc, hasAttachments, attachments));
        }
예제 #19
0
        protected override ActionResult DoActionProcessing(Job job)
        {
            var smtpAccount = job.Accounts.GetSmtpAccount(job.Profile);

            if (string.IsNullOrEmpty(job.Passwords.SmtpPassword))
            {
                Logger.Error("SendMailOverSmtp canceled. Action launched without Password.");
                return(new ActionResult(ErrorCode.Smtp_NoPasswordSpecified));
            }

            MailMessage mail;

            try
            {
                mail = new MailMessage(smtpAccount.Address, job.Profile.EmailSmtpSettings.Recipients);
            }
            catch (Exception e) when(e is FormatException || e is ArgumentException)
            {
                Logger.Error($"\'{job.Profile.EmailSmtpSettings.Recipients}\' is no valid SMTP e-mail recipient: " + e.Message);
                return(new ActionResult(ErrorCode.Smtp_InvalidRecipients));
            }

            // these blocks have to be seperated, because we want to log the offending recipients
            // (AddRecipients does this already, but can't be reused for the constructor)
            try
            {
                AddRecipients(mail, RecipientType.Cc, job.Profile.EmailSmtpSettings.RecipientsCc);
                AddRecipients(mail, RecipientType.Bcc, job.Profile.EmailSmtpSettings.RecipientsBcc);
            }
            catch
            {
                return(new ActionResult(ErrorCode.Smtp_InvalidRecipients));
            }

            mail.Subject    = job.TokenReplacer.ReplaceTokens(job.Profile.EmailSmtpSettings.Subject);
            mail.IsBodyHtml = job.Profile.EmailSmtpSettings.Html;
            mail.Body       = job.TokenReplacer.ReplaceTokens(job.Profile.EmailSmtpSettings.Content);

            if (job.Profile.EmailSmtpSettings.AddSignature)
            {
                var mailSignature = _mailSignatureHelper.ComposeMailSignature();

                // if html option is checked replace newLine with <br />
                if (job.Profile.EmailSmtpSettings.Html)
                {
                    mailSignature = mailSignature.Replace(Environment.NewLine, "<br>");
                }

                mail.Body += mailSignature;
            }

            Logger.Debug("Created new Mail"
                         + "\r\nFrom: " + mail.From
                         + "\r\nTo: " + mail.To
                         + "\r\nSubject: " + mail.Subject
                         + "\r\nContent: " + mail.Body
                         );

            if (!SkipFileAttachments(job))
            {
                var i = 1;
                foreach (var file in job.OutputFiles)
                {
                    var attach = new Attachment(file);
                    //attach.NameEncoding = System.Text.Encoding.ASCII;
                    mail.Attachments.Add(attach);
                    Logger.Debug("Attachement " + i + "/" + job.OutputFiles.Count + ":" + file);
                    i++;
                }
            }

            var smtp = new SmtpClient(smtpAccount.Server, smtpAccount.Port);

            smtp.EnableSsl = smtpAccount.Ssl;

            Logger.Debug("Created new SmtpClient:"
                         + "\r\nHost: " + smtp.Host
                         + "\r\nPort: " + smtp.Port
                         );

            return(SendEmail(job, smtp, mail));
        }