public void EmailSourceToXmlExpectedSerializesProperties()
        {
            var expected = new EmailSource
            {
                Host            = "smtp.mydomain.com",
                Port            = 25,
                EnableSsl       = false,
                UserName        = "******",
                Password        = "******",
                Timeout         = 1000,
                TestFromAddress = "*****@*****.**",
                TestToAddress   = "*****@*****.**"
            };

            var xml = expected.ToXml();

            var actual = new EmailSource(xml);

            Assert.AreEqual(expected.ResourceType, actual.ResourceType);
            Assert.AreEqual(expected.Host, actual.Host);
            Assert.AreEqual(expected.Port, actual.Port);
            Assert.AreEqual(expected.EnableSsl, actual.EnableSsl);
            Assert.AreEqual(expected.UserName, actual.UserName);
            Assert.AreEqual(expected.Password, actual.Password);
            Assert.AreEqual(expected.Timeout, actual.Timeout);
            Assert.IsNull(actual.TestFromAddress);
            Assert.IsNull(actual.TestToAddress);
        }
        void Verify_Constructor_DoesNotAutoCopyEmailSourceUserNameIntoFromAccount(string expectedFromAccount)
        {
            //------------Setup for test--------------------------
            var activity = new DsfSendEmailActivity {
                FromAccount = expectedFromAccount
            };

            var emailSource = new EmailSource
            {
                UserName   = "******",
                Password   = "******",
                EnableSsl  = false,
                Host       = "mx.mydomain.com",
                Port       = 25,
                ResourceID = Guid.NewGuid()
            };
            var modelItem = ModelItemUtils.CreateModelItem(activity);
            var viewModel = CreateViewModel(null, modelItem);

            //------------Execute Test---------------------------
            viewModel.SelectedEmailSource = emailSource;

            //------------Assert Results-------------------------
            var fromAccount = modelItem.GetProperty <string>("FromAccount");

            Assert.AreEqual(expectedFromAccount, fromAccount);
        }
Esempio n. 3
0
        void TestEmailAccount()
        {
            var testEmailAccount = GetTestEmailAccount();

            if (string.IsNullOrEmpty(testEmailAccount))
            {
                return;
            }
            CanTestEmailAccount = false;

            var testSource = new EmailSource(SelectedEmailSource.ToXml());

            if (!string.IsNullOrEmpty(FromAccount))
            {
                testSource.UserName = FromAccount;
                testSource.Password = Password;
            }
            testSource.TestFromAddress = testSource.UserName;
            testSource.TestToAddress   = testEmailAccount;

            Uri uri      = new Uri(new Uri(AppSettings.LocalHost), "wwwroot/sources/Service/EmailSources/Test");
            var jsonData = testSource.ToString();

            var requestInvoker = CreateWebRequestInvoker();

            requestInvoker.ExecuteRequest("POST", uri.ToString(), jsonData, null, OnTestCompleted);
        }
Esempio n. 4
0
        public IEmailServiceSource FetchSource(Guid resourceID)
        {
            var xaml = _queryProxy.FetchResourceXaml(resourceID);
            var db   = new EmailSource(xaml.ToXElement());

            var def = new EmailServiceSourceDefinition(db);

            return(def);
        }
        public void EmailSourceContructorWithDefaultExpectedInitializesProperties()
        {
            var source = new EmailSource();

            Assert.AreEqual(Guid.Empty, source.ResourceID);
            Assert.AreEqual(ResourceType.EmailSource, source.ResourceType);
            Assert.AreEqual(EmailSource.DefaultTimeout, source.Timeout);
            Assert.AreEqual(EmailSource.DefaultPort, source.Port);
        }
Esempio n. 6
0
 public static EmailTemplate Fetch(EmailSource src, string identifier) {
     switch (src) {
         case EmailSource.EmbeddedResource:
             return Resource(identifier);
         case EmailSource.File:
             return File(identifier);
         default:
             throw new ArgumentOutOfRangeException(nameof(src), src, null);
     }
 }
Esempio n. 7
0
        public void NextValue()
        {
            var source = new EmailSource();

            for (int i = 0; i < 10; i++)
            {
                var nextValue = source.NextValue(null);
                _output.WriteLine($"Value {i}: {nextValue}");
            }
        }
        public void DeleteRelatedRecords()
        {
            // Arrange
            const string SerialNumber = "21938726391232312342";

            Record record;

            using (var session = SessionFactory.OpenSession())
            {
                record = new Record()
                {
                    ReadDatetime = DateTime.Now,
                    SerialNumber = SerialNumber
                };

                session.Save(record);

                var emailSource = new EmailSource()
                {
                    Content = Encoding.UTF8.GetBytes("Content"),
                    Id      = record.Id
                };

                var htmlCounterSource = new ServiceSourceCounters()
                {
                    Content = "Content",
                    Id      = record.Id
                };

                var htmlNumberSource = new ServiceSourceSerialNumber()
                {
                    Content = "Content",
                    Id      = record.Id
                };

                session.Save(htmlCounterSource);
                session.Save(htmlNumberSource);

                session.Flush();
            }

            // Act
            using (var session = SessionFactory.OpenSession())
            {
                session.Delete(record);
                session.Flush();
            }

            // Assert
            using (var session = SessionFactory.OpenSession())
            {
                var rec = session.Get <Record>(record.Id);
                Assert.IsNull(rec);
            }
        }
Esempio n. 9
0
        public void EmailSourcesTestWithInvalidHostExpectedInvalidValidationResult()
        {
            var source = new EmailSource {
                Host = "smtp.foobar.com", Port = 25
            }.ToString();

            var handler = new EmailSources();
            var result  = handler.Test(source, Guid.Empty, Guid.Empty);

            Assert.IsFalse(result.IsValid, result.ErrorMessage);
        }
Esempio n. 10
0
        static Mock <IEsbChannel> CreateMockEsbChannel(EmailSource emailSourceForTesting)
        {
            Mock <IEsbChannel> esbChannelMock = new Mock <IEsbChannel>();
            ErrorResultTO      errorResultTO;

            esbChannelMock.Setup(channel => channel.FetchServerModel <EmailSource>(
                                     It.IsAny <IDSFDataObject>(),
                                     It.IsAny <Guid>(),
                                     out errorResultTO)).Returns(emailSourceForTesting);
            return(esbChannelMock);
        }
        public void EmailSourceContructorWithInvalidXmlExpectedDoesNotThrowExceptionAndInitializesProperties()
        {
            var xml    = new XElement("root");
            var source = new EmailSource(xml);

            Assert.AreNotEqual(Guid.Empty, source.ResourceID);
            Assert.IsTrue(source.IsUpgraded);
            Assert.AreEqual(ResourceType.EmailSource, source.ResourceType);
            Assert.AreEqual(EmailSource.DefaultTimeout, source.Timeout);
            Assert.AreEqual(EmailSource.DefaultPort, source.Port);
        }
Esempio n. 12
0
        public void EmailSource_Validate_DataList()
        {
            const string expectedDataList = "data list";

            var source = new EmailSource
            {
                DataList = expectedDataList
            };

            Assert.AreEqual(expectedDataList, source.DataList);
        }
Esempio n. 13
0
 public void Send()
 {
     if (EmailSource == null)
     {
         throw new NoNullAllowedException("Please set SmtpClient");
     }
     if (MailMessage == null)
     {
         throw new NoNullAllowedException("Please set MailMessage");
     }
     EmailSource.Send(MailMessage);
 }
Esempio n. 14
0
        static EmailSource EmailSourceForTesting()
        {
            var emailSourceForTesting = new EmailSource();

            emailSourceForTesting.ResourceName = Guid.NewGuid().ToString();
            emailSourceForTesting.ResourceID   = Guid.NewGuid();
            emailSourceForTesting.Host         = "TestHost";
            emailSourceForTesting.UserName     = "******";
            emailSourceForTesting.Password     = "******";
            ResourceCatalog.Instance.SaveResource(Guid.Empty, emailSourceForTesting);
            return(emailSourceForTesting);
        }
Esempio n. 15
0
        protected override void BuildDataList()
        {
            scenarioContext.TryGetValue("variableList", out List <Tuple <string, string> > variableList);

            if (variableList == null)
            {
                variableList = new List <Tuple <string, string> >();
                scenarioContext.Add("variableList", variableList);
            }

            variableList.Add(new Tuple <string, string>(ResultVariable, ""));
            BuildShapeAndTestData();

            scenarioContext.TryGetValue("body", out string body);
            scenarioContext.TryGetValue("subject", out string subject);
            scenarioContext.TryGetValue("fromAccount", out string fromAccount);
            scenarioContext.TryGetValue("password", out string password);
            scenarioContext.TryGetValue("simulationOutput", out string simulationOutput);
            scenarioContext.TryGetValue("to", out string to);
            scenarioContext.TryGetValue("isHtml", out bool isHtml);

            var server = SimpleSmtpServer.Start(25);

            scenarioContext.Add("server", server);

            var selectedEmailSource = new EmailSource
            {
                Host         = "localhost",
                Port         = 25,
                UserName     = "",
                Password     = "",
                ResourceName = Guid.NewGuid().ToString(),
                ResourceID   = Guid.NewGuid()
            };

            ResourceCatalog.Instance.SaveResource(Guid.Empty, selectedEmailSource, "");
            var sendEmail = new DsfSendEmailActivity
            {
                Result              = ResultVariable,
                Body                = string.IsNullOrEmpty(body) ? "" : body,
                Subject             = string.IsNullOrEmpty(subject) ? "" : subject,
                FromAccount         = string.IsNullOrEmpty(fromAccount) ? "" : fromAccount,
                To                  = string.IsNullOrEmpty(to) ? "" : to,
                SelectedEmailSource = selectedEmailSource,
                IsHtml              = isHtml
            };

            TestStartNode = new FlowStep
            {
                Action = sendEmail
            };
            scenarioContext.Add("activity", sendEmail);
        }
        public async Task <IActionResult> SendWelcomeMail([FromForm] EmailSource source)
        {
            try
            {
                await mailService.SendEmailTemplateAsync(source);

                return(Ok());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 17
0
        public void EmailSourceContructorWithCorruptXmlExpectedInitializesProperties()
        {
            var xml = XmlResource.Fetch("EmailSourceCorrupt");

            var source = new EmailSource(xml);

            Assert.AreEqual(Guid.Parse("bf810e43-3633-4638-9d0a-56473ef54151"), source.ResourceID);
            Assert.AreEqual(nameof(EmailSource), source.ResourceType);
            Assert.AreEqual("smtp.gmail.com", source.Host);
            Assert.AreEqual(EmailSource.DefaultPort, source.Port);
            Assert.AreEqual(false, source.EnableSsl);
            Assert.AreEqual(EmailSource.DefaultTimeout, source.Timeout);
            Assert.AreEqual("*****@*****.**", source.UserName);
            Assert.AreEqual("1234", source.Password);
        }
        public void EmailSourceContructorWithValidXmlExpectedInitializesProperties()
        {
            var xml = XmlResource.Fetch("EmailSource");

            var source = new EmailSource(xml);

            Assert.AreEqual(Guid.Parse("bf810e43-3633-4638-9d0a-56473ef54151"), source.ResourceID);
            Assert.AreEqual(ResourceType.EmailSource, source.ResourceType);
            Assert.AreEqual("smtp.gmail.com", source.Host);
            Assert.AreEqual(465, source.Port);
            Assert.AreEqual(true, source.EnableSsl);
            Assert.AreEqual(30000, source.Timeout);
            Assert.AreEqual("*****@*****.**", source.UserName);
            Assert.AreEqual("1234", source.Password);
        }
Esempio n. 19
0
        protected virtual void OnSelectedEmailSourceChanged()
        {
            if (SelectedEmailSource == NewEmailSource)
            {
                CreateEmailSource();
                return;
            }

            IsRefreshing = true;

            if (SelectedEmailSource != SelectEmailSource)
            {
                EmailSources.Remove(SelectEmailSource);
            }
            EmailSource = SelectedEmailSource;
        }
Esempio n. 20
0
        public void EmailSourceContructorWithDefaultExpectedInitializesProperties()
        {
            var source = new EmailSource();

            Assert.AreEqual(Guid.Empty, source.ResourceID);
            Assert.AreEqual(nameof(EmailSource), source.ResourceType);
            Assert.AreEqual(EmailSource.DefaultTimeout, source.Timeout);
            Assert.AreEqual(EmailSource.DefaultPort, source.Port);
            Assert.IsNull(source.DataList);
            Assert.IsTrue(source.IsSource);
            Assert.IsFalse(source.IsService);
            Assert.IsFalse(source.IsFolder);
            Assert.IsFalse(source.IsReservedService);
            Assert.IsFalse(source.IsServer);
            Assert.IsFalse(source.IsResourceVersion);
        }
Esempio n. 21
0
        static void VerifySource(EmailSource actual, EmailSource expected)
        {
            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.ResourceID, actual.ResourceID);
            Assert.AreEqual(expected.ResourceName, actual.ResourceName);
            Assert.AreEqual(expected.ResourcePath, actual.ResourcePath);
            Assert.AreEqual(expected.ResourceType, actual.ResourceType);
            Assert.AreEqual(expected.ResourceType, actual.ResourceType);

            Assert.AreEqual(expected.Host, actual.Host);
            Assert.AreEqual(expected.Port, actual.Port);
            Assert.AreEqual(expected.EnableSsl, actual.EnableSsl);
            Assert.AreEqual(expected.UserName, actual.UserName);
            Assert.AreEqual(expected.Password, actual.Password);
            Assert.AreEqual(expected.Timeout, actual.Timeout);
        }
Esempio n. 22
0
        ValidationResult CanConnectServer(EmailSource emailSource)
        {
            try
            {
                var userParts = emailSource.UserName.Split(new[] { '@' });

                var smtp = new SmtpClient(emailSource.Host, emailSource.Port)
                {
                    Credentials    = new NetworkCredential(userParts[0], emailSource.Password),
                    EnableSsl      = emailSource.EnableSsl,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    Timeout        = emailSource.Timeout
                };

                try
                {
                    smtp.Send(emailSource.TestFromAddress, emailSource.TestToAddress, "Test Message", "This is a test message");
                    return(new ValidationResult());
                }
                finally
                {
                    smtp.Dispose();
                }
            }
            catch (SmtpException sex)
            {
                RaiseError(sex);
                var message = sex.Message;
                if (sex.StatusCode == SmtpStatusCode.MustIssueStartTlsFirst && sex.Message.Contains("Learn more at"))
                {
                    message = message.Replace(" Learn more at", "");
                }
                var errors = new StringBuilder();
                errors.AppendFormat("{0} ", message);
                Exception ex = sex.InnerException;
                while (ex != null)
                {
                    errors.AppendFormat("{0} ", ex.Message);
                    ex = ex.InnerException;
                }
                return(new ValidationResult
                {
                    IsValid = false,
                    ErrorMessage = errors.ToString()
                });
            }
        }
        public void EmailDesignerViewModel_Handles_UpdateResourceMessage_EmailSourceIsUpdated()
        {
            //------------Setup for test--------------------------
            var resourceID  = Guid.NewGuid();
            var emailSource = new EmailSource
            {
                ResourceID   = resourceID,
                ResourceName = "Email1",
                UserName     = "******",
                Password     = "******"
            };

            // var emailSources = CreateEmailSources(2);
            var modelItem = ModelItemUtils.CreateModelItem(new DsfSendEmailActivity
            {
                SelectedEmailSource = emailSource
            });

            var viewModel = CreateViewModel(new List <EmailSource> {
                emailSource
            }, modelItem);

            var updatedEmailSource = new EmailSource
            {
                ResourceID   = resourceID,
                ResourceName = "EmailTest",
                UserName     = "******",
                Password     = "******"
            };

            //var xaml = new StringBuilder
            var resourceModel = new Mock <IContextualResourceModel>();

            resourceModel.Setup(r => r.WorkflowXaml).Returns(new StringBuilder(updatedEmailSource.ToXml().ToString()));

            var message = new UpdateResourceMessage(resourceModel.Object);

            //------------Execute Test---------------------------
            viewModel.Handle(message);

            //------------Assert Results-------------------------
            var selectedSource = viewModel.SelectedEmailSourceModelItemValue;

            Assert.AreEqual(updatedEmailSource.UserName, selectedSource.UserName);
            Assert.AreEqual(updatedEmailSource.Password, selectedSource.Password);
        }
Esempio n. 24
0
        public void Handle(UpdateResourceMessage message)
        {
            var selectedSource = new EmailSource(message.ResourceModel.WorkflowXaml.ToXElement());

            if (EmailSource == null)
            {
                EmailSource = selectedSource;
            }
            else
            {
                if (selectedSource.ResourceID == EmailSource.ResourceID)
                {
                    EmailSource = null;
                    EmailSource = selectedSource;
                }
            }
        }
Esempio n. 25
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            ExecuteMessage     msg        = new ExecuteMessage();
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();

            try
            {
                Dev2Logger.Info("Save Resource Service");
                StringBuilder resourceDefinition;

                values.TryGetValue("EmailServiceSource", out resourceDefinition);

                IEmailServiceSource src = serializer.Deserialize <EmailServiceSourceDefinition>(resourceDefinition);
                EmailSource         con = new EmailSource
                {
                    Host      = src.HostName,
                    UserName  = src.UserName,
                    Password  = src.Password,
                    Port      = src.Port,
                    EnableSsl = src.EnableSsl,
                    Timeout   = src.Timeout
                };
                try
                {
                    con.Send(new MailMessage(src.EmailFrom, src.EmailTo, "Test Email Service Source", "Test message from Warewolf for Email Service Source"));
                }
                catch (SmtpException e)
                {
                    msg.HasError = false;
                    msg.Message  = new StringBuilder(e.Message);
                    return(serializer.SerializeToBuilder(msg));
                    //msg.HasError = true;
                    //msg.Message = new StringBuilder(e.Message);
                }
            }
            catch (Exception err)
            {
                msg.HasError = true;
                msg.Message  = new StringBuilder(err.Message);
                Dev2Logger.Error(err);
            }

            return(serializer.SerializeToBuilder(msg));
        }
Esempio n. 26
0
        // POST: Service/EmailSources/Get
        public EmailSource Get(string resourceId, Guid workspaceId, Guid dataListId)
        {
            var result = new EmailSource();

            try
            {
                var xmlStr = ResourceCatalog.Instance.GetResourceContents(workspaceId, Guid.Parse(resourceId)).ToString();
                if (!string.IsNullOrEmpty(xmlStr))
                {
                    var xml = XElement.Parse(xmlStr);
                    result = new EmailSource(xml);
                }
            }
            catch (Exception ex)
            {
                RaiseError(ex);
            }
            return(result);
        }
Esempio n. 27
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var msg        = new ExecuteMessage();
            var serializer = new Dev2JsonSerializer();

            try
            {
                Dev2Logger.Info("Save Resource Service", GlobalConstants.WarewolfInfo);

                values.TryGetValue("EmailServiceSource", out StringBuilder resourceDefinition);

                IEmailServiceSource src = serializer.Deserialize <EmailServiceSourceDefinition>(resourceDefinition);
                var con = new EmailSource
                {
                    Host      = src.HostName,
                    UserName  = src.UserName,
                    Password  = src.Password,
                    Port      = src.Port,
                    EnableSsl = src.EnableSsl,
                    Timeout   = src.Timeout
                };
                try
                {
                    var mailMessage = new MailMessage(src.EmailFrom, src.EmailTo, Messages.Test_EmailServerSource_Header, Messages.Test_EmailServerSource_EmailBody);
                    con.Send(mailMessage);
                }
                catch (SmtpException e)
                {
                    msg.HasError = true;
                    msg.Message  = new StringBuilder(e.Message);
                    return(serializer.SerializeToBuilder(msg));
                }
            }
            catch (Exception err)
            {
                msg.HasError = true;
                msg.Message  = new StringBuilder(err.Message);
                Dev2Logger.Error(err, GlobalConstants.WarewolfError);
            }

            return(serializer.SerializeToBuilder(msg));
        }
Esempio n. 28
0
        public void EmailSource_Send_ExpectedException()
        {
            var expected = new EmailSource
            {
                Host            = "smtp.mydomain.com",
                Port            = 25,
                EnableSsl       = false,
                UserName        = "******",
                Password        = "******",
                Timeout         = 1000,
                TestFromAddress = "*****@*****.**",
                TestToAddress   = "*****@*****.**"
            };

            var xml = expected.ToXml();

            var mailMessage = new MailMessage();
            var emailSource = new EmailSource(xml);

            emailSource.Send(mailMessage);
        }
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            ExecuteMessage     msg        = new ExecuteMessage();
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();

            try
            {
                Dev2Logger.Info("Save Email Service Source");
                StringBuilder resourceDefinition;

                values.TryGetValue("EmailServiceSource", out resourceDefinition);

                IEmailServiceSource src = serializer.Deserialize <IEmailServiceSource>(resourceDefinition);
                EmailSource         con = new EmailSource
                {
                    Host         = src.HostName,
                    UserName     = src.UserName,
                    Password     = src.Password,
                    Port         = src.Port,
                    EnableSsl    = src.EnableSsl,
                    Timeout      = src.Timeout,
                    ResourceName = src.ResourceName,
                    ResourceID   = src.Id
                };
                ResourceCatalog.Instance.SaveResource(GlobalConstants.ServerWorkspaceID, con, src.Path);
                ServerExplorerRepo.UpdateItem(con);

                msg.HasError = false;
            }
            catch (Exception err)
            {
                msg.HasError = true;
                msg.Message  = new StringBuilder(err.Message);
                Dev2Logger.Error(err);
            }

            return(serializer.SerializeToBuilder(msg));
        }
        public async Task SendEmailTemplateAsync(EmailSource emailSource)
        {
            string       FilePath = Directory.GetCurrentDirectory() + "\\Templates\\CustomTemplate.html";
            StreamReader str      = new StreamReader(FilePath);
            string       MailText = str.ReadToEnd();

            str.Close();
            MailText = MailText.Replace("[username]", emailSource.UserName).Replace("[email]", emailSource.EmailTo);
            var email = new MimeMessage();

            email.Sender = MailboxAddress.Parse(_mailSettings.EMail);
            email.To.Add(MailboxAddress.Parse(emailSource.EmailTo));
            email.Subject = $"Welcome {emailSource.UserName}";
            var builder = new BodyBuilder();

            builder.HtmlBody = MailText;
            email.Body       = builder.ToMessageBody();
            using var smtp   = new SmtpClient();
            smtp.Connect(_mailSettings.Host, _mailSettings.Port, SecureSocketOptions.StartTls);
            smtp.Authenticate(_mailSettings.EMail, _mailSettings.Password);
            await smtp.SendAsync(email);

            smtp.Disconnect(true);
        }
Esempio n. 31
0
        void TestEmailAccount()
        {
            var testEmailAccount = GetTestEmailAccount();

            if (string.IsNullOrEmpty(testEmailAccount))
            {
                Errors = new List <IActionableErrorInfo> {
                    new ActionableErrorInfo(() => IsToFocused = true)
                    {
                        Message = "Please supply a To address in order to Test."
                    }
                };
                return;
            }
            CanTestEmailAccount = false;

            var testSource = new EmailSource(SelectedEmailSource.ToXml());

            if (!string.IsNullOrEmpty(FromAccount))
            {
                testSource.UserName = FromAccount;
                testSource.Password = Password;
            }
            testSource.TestFromAddress = testSource.UserName;
            testSource.TestToAddress   = testEmailAccount;
            if (EmailAddresssIsAVariable(testEmailAccount))
            {
                return;
            }
            Uri uri      = new Uri(new Uri(AppSettings.LocalHost), "wwwroot/sources/Service/EmailSources/Test");
            var jsonData = testSource.ToString();

            var requestInvoker = CreateWebRequestInvoker();

            requestInvoker.ExecuteRequest("POST", uri.ToString(), jsonData, null, OnTestCompleted);
        }
Esempio n. 32
0
File: Email.cs Progetto: Nucs/nlib
        /// <summary>
        ///     Sends a templated email.
        /// </summary>
        /// <param name="sender">Which email address sends this email</param>
        /// <param name="receiver">The receiver of the email</param>
        /// <param name="subject">Subject of the email</param>
        /// <param name="body">Content of the email</param>
        /// <param name="source">Which source refer to</param>
        /// <param name="identifier">Depends on the EmailSource, if File then a path, if Resource then the resource name.</param>
        public async Task SendTemplate(MailAddress sender, MailAddress receiver, string subject, string body, EmailSource source, string identifier) {
            var template = EmailSources.Fetch(source, identifier);
            if (template == null)
                throw new FileNotFoundException($"Template could not have been found!\n Source: {source}, Identifier: {identifier}");

            var msg = _prepareNewMail;
            msg.Sender = sender;
            msg.From = sender;
            msg.To.Add(receiver);
            msg.Subject = subject ?? "No Subject";
            msg.Body = body ?? "";

            //new translated body
            msg.Body = msg.Translate(template);
            await _internal_sendasyncmail(msg);
        }
Esempio n. 33
0
File: Email.cs Progetto: Nucs/nlib
 /// <summary>
 ///     Sends a templated email.
 /// </summary>
 /// <param name="sender">Which email address sends this email</param>
 /// <param name="receiver">The receiver of the email</param>
 /// <param name="subject">Subject of the email</param>
 /// <param name="body">Content of the email</param>
 /// <param name="source">Which source refer to</param>
 /// <param name="identifier">Depends on the EmailSource, if File then a path, if Resource then the resource name.</param>
 public async Task SendTemplate(MailAddress sender, string receiver, string subject, EmailSource source, string identifier) {
     await SendTemplate(sender, new MailAddress(receiver), subject, null, source, identifier);
 }
Esempio n. 34
0
File: Email.cs Progetto: Nucs/nlib
 /// <summary>
 ///     Sends a templated email.
 /// </summary>
 /// <param name="sender">Which email address sends this email</param>
 /// <param name="receiver">The receiver of the email</param>
 /// <param name="subject">Subject of the email</param>
 /// <param name="body">Content of the email</param>
 /// <param name="source">Which source refer to</param>
 /// <param name="identifier">Depends on the EmailSource, if File then a path, if Resource then the resource name.</param>
 public async Task SendTemplate(string sender, string receiver, string subject, Body body, EmailSource source, string identifier) {
     await SendTemplate(new MailAddress(sender), new MailAddress(receiver), subject, body.Content, source, identifier);
 }
Esempio n. 35
0
File: Email.cs Progetto: Nucs/nlib
 /// <summary>
 ///     Sends a templated email.
 /// </summary>
 /// <param name="sender">Which email address sends this email</param>
 /// <param name="receiver">The receiver of the email</param>
 /// <param name="subject">Subject of the email</param>
 /// <param name="body">Content of the email</param>
 /// <param name="source">Which source refer to</param>
 /// <param name="identifier">Depends on the EmailSource, if File then a path, if Resource then the resource name.</param>
 public async Task SendTemplate(MailAddress receiver, string subject, Body body, EmailSource source, string identifier) {
     await SendTemplate(new MailAddress(DefaultSender, DefaultSenderDisplayName), receiver, subject, body.Content, source, identifier);
 }
Esempio n. 36
0
File: Email.cs Progetto: Nucs/nlib
 /// <summary>
 ///     Sends a templated email.
 /// </summary>
 /// <param name="sender">Which email address sends this email</param>
 /// <param name="receiver">The receiver of the email</param>
 /// <param name="subject">Subject of the email</param>
 /// <param name="body">Content of the email</param>
 /// <param name="source">Which source refer to</param>
 /// <param name="identifier">Depends on the EmailSource, if File then a path, if Resource then the resource name.</param>
 public async Task SendTemplate(string receiver, string subject, EmailSource source, string identifier) {
     await SendTemplate(new MailAddress(DefaultSender, DefaultSenderDisplayName), new MailAddress(receiver), subject, null, source, identifier);
 }