private SmtpClient CreateSmtpClient(IModelSmtpClientContext modelSmtpClientContext) { var smtpClient = new SmtpClient { DeliveryMethod = modelSmtpClientContext.DeliveryMethod, }; if (!string.IsNullOrEmpty(modelSmtpClientContext.PickupDirectoryLocation)) { smtpClient.PickupDirectoryLocation = Path.GetFullPath(Environment.ExpandEnvironmentVariables(modelSmtpClientContext.PickupDirectoryLocation)); } if (smtpClient.DeliveryMethod == SmtpDeliveryMethod.Network) { smtpClient.Host = modelSmtpClientContext.Host; smtpClient.Port = modelSmtpClientContext.Port; smtpClient.EnableSsl = modelSmtpClientContext.EnableSsl; smtpClient.UseDefaultCredentials = modelSmtpClientContext.UseDefaultCredentials; if (!smtpClient.UseDefaultCredentials) { smtpClient.Credentials = new NetworkCredential(modelSmtpClientContext.UserName, modelSmtpClientContext.Password); } } else { if (!string.IsNullOrEmpty(smtpClient.PickupDirectoryLocation) && !Directory.Exists(smtpClient.PickupDirectoryLocation)) { Directory.CreateDirectory(smtpClient.PickupDirectoryLocation); } } return(smtpClient); }
EmailTemplateEngine.Email CreateEmail(LogicRuleInfo logicRuleInfo, EmailRule emailRule, IModelSmtpClientContext modelSmtpClientContext, IEmailTemplate emailTemplateObject, IModelApplicationEmail modelApplicationEmail) { var templateEngine = new EmailTemplateEngine.EmailTemplateEngine(emailTemplateObject); var email = templateEngine.Execute(logicRuleInfo.Object, emailRule.ID); if (emailRule.CurrentObjectEmailMember != null) { var toEmail = emailRule.CurrentObjectEmailMember.MemberInfo.GetValue(logicRuleInfo.Object) as string; email.To.Add(toEmail); } if (!string.IsNullOrEmpty(emailRule.EmailReceipientsContext)) { AddReceipients(emailRule, modelApplicationEmail, email,logicRuleInfo.Object); } email.From = modelSmtpClientContext.SenderEmail; modelSmtpClientContext.ReplyToEmails.Split(';').Each(s => email.ReplyTo.Add(s)); return email.To.Count == 0 ? null : email; }
private SmtpClient CreateSmtpClient(IModelSmtpClientContext modelSmtpClientContext) { var smtpClient = new SmtpClient { DeliveryMethod = SmtpDeliveryMethod.Network, Host = modelSmtpClientContext.Host, Port = modelSmtpClientContext.Port, EnableSsl = modelSmtpClientContext.EnableSsl, UseDefaultCredentials = modelSmtpClientContext.UseDefaultCredentials }; if (!smtpClient.UseDefaultCredentials) { smtpClient.Credentials = new NetworkCredential( modelSmtpClientContext.UserName, modelSmtpClientContext.Password); } return(smtpClient); }
protected virtual MailMessage CreateEmail(LogicRuleInfo logicRuleInfo, EmailRule emailRule, IModelSmtpClientContext modelSmtpClientContext, IEmailTemplate emailTemplateObject, IModelApplicationEmail modelApplicationEmail) { var body = RazorEngineService.RunCompile(emailTemplateObject.Body, Guid.NewGuid().ToString(), null, logicRuleInfo.Object); var email = new MailMessage { IsBodyHtml = true, Subject = RazorEngineService.RunCompile(emailTemplateObject.Subject, Guid.NewGuid().ToString(), null, logicRuleInfo.Object), Body = body }; var toEmail = emailRule.CurrentObjectEmailMember?.MemberInfo.GetValue(logicRuleInfo.Object) as string; toEmail?.Split(';').Each(s => email.To.Add(s)); if (!string.IsNullOrEmpty(emailRule.EmailReceipientsContext)) { AddReceipients(emailRule, modelApplicationEmail, email, logicRuleInfo.Object); } email.From = new MailAddress(modelSmtpClientContext.SenderEmail); modelSmtpClientContext.ReplyToEmails.Split(';').Each(s => email.ReplyToList.Add(s)); return(email.To.Count == 0 ? null : email); }
EmailTemplateEngine.Email CreateEmail(EmailTemplateEngine.EmailTemplateEngine templateEngine, LogicRuleInfo logicRuleInfo, EmailRule emailRule, IModelSmtpClientContext modelSmtpClientContext, IEmailTemplate emailTemplateObject, IModelApplicationEmail modelApplicationEmail) { var email = templateEngine.Execute(logicRuleInfo.Object, emailRule.ID); if (emailRule.CurrentObjectEmailMember != null) { var toEmail = emailRule.CurrentObjectEmailMember.MemberInfo.GetValue(logicRuleInfo.Object) as string; email.To.Add(toEmail); } if (!string.IsNullOrEmpty(emailRule.EmailReceipientsContext)) { AddReceipients(emailRule, modelApplicationEmail, email, logicRuleInfo.Object); } email.From = modelSmtpClientContext.SenderEmail; email.Subject = emailTemplateObject.Subject; modelSmtpClientContext.ReplyToEmails.Split(';').Each(s => email.ReplyTo.Add(s)); return(email.To.Count == 0 ? null : email); }
private SmtpClient CreateSmtpClient(IModelSmtpClientContext modelSmtpClientContext) { var smtpClient = new SmtpClient { DeliveryMethod = SmtpDeliveryMethod.Network, Host = modelSmtpClientContext.Host, Port = modelSmtpClientContext.Port, EnableSsl = modelSmtpClientContext.EnableSsl, UseDefaultCredentials = modelSmtpClientContext.UseDefaultCredentials }; if (!smtpClient.UseDefaultCredentials) { smtpClient.Credentials = new NetworkCredential( modelSmtpClientContext.UserName, modelSmtpClientContext.Password); } return smtpClient; }