public void CanProcessTemplateWithOnlyToken() { const string templateBody = "{ReferenceName}"; var processing = new TemplateProcessing(); var templateResult = processing.ProcessTemplate(reference, application, templateBody); var templateReplace = templateResult.Replace("{ReferenceName}", reference.FullName); Assert.IsNotNull(templateResult); Assert.AreEqual(templateReplace, templateResult); }
public void CanProcessTemplateByReplacingRecruitmentAdmin() { const string templateBody = "Who is the {RecruitmentAdminName}"; var processing = new TemplateProcessing(); var templateResult = processing.ProcessTemplate(reference, application, templateBody); var templateReplace = templateResult.Replace("{RecruitmentAdminName}", application.AppliedPosition.HRRep); Assert.IsNotNull(templateResult); Assert.AreEqual(templateReplace, templateResult); }
/// <summary> /// Send a email from the given positions's HR Rep to the given reference's email account. On success the reference is marked as being /// sent the email so she will not be sent another. The automated email account is BCC'd for reference. /// </summary> /// <returns>Returns null on success, else returns the name of the offending reference and applicant</returns> private string sendReferenceEmail(Position position, Application application, Reference reference) { TemplateProcessing template = new TemplateProcessing(); //Process the template to get the body text of the email string bodyText = template.ProcessTemplate(reference, application, position.ReferenceTemplate.TemplateText, true); //Exchange Ops is commented out because it will not send HTML emails currently (also needs MSXML2) //Now configure the email host //CAESDO.ExchangeOps exops = new ExchangeOps(); //exops.ConfigureServer(WebConfigurationManager.AppSettings["ServerName"], WebConfigurationManager.AppSettings["Protocol"]); //exops.ConfigureEmail(WebConfigurationManager.AppSettings["emailDomainUserName"], WebConfigurationManager.AppSettings["emailUserName"], WebConfigurationManager.AppSettings["emailPassword"]); System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient(); //Try to send the email -- if there are errors, return the email of the offending reference try { System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(currentPosition.HREmail, reference.Email, "Reference Request for " + application.AssociatedProfile.FullName, bodyText); message.Bcc.Add(WebConfigurationManager.AppSettings["AppMailTo"]); //BCC the recruitments email account message.IsBodyHtml = true; //System.IO.FileStream descriptionStream = new System.IO.FileStream(FilePath + position.DescriptionFile.ID, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); //message.Attachments.Add(new System.Net.Mail.Attachment(descriptionStream, position.DescriptionFile.FileName)); mail.Send(message); //After the message is sent, close the stream. //descriptionStream.Close(); //exops.SendEmail(reference.Email, "Reference Request for Application" + position.PositionTitle, bodyText, WebConfigurationManager.AppSettings["emailFromEmail"]); } catch (Exception) { return(string.Format("{0} ({1})", reference.FullName, application.AssociatedProfile.FullName)); } //No errors, so save the fact that we sent an email to the current reference using (var ts = new TransactionScope()) { reference.SentEmail = true; reference.EmailDate = DateTime.Now; ReferenceBLL.EnsurePersistent(reference); ts.CommitTransaction(); } return(null); }
public string GetTemplatePreview(string templateBody) { var processing = new TemplateProcessing(); var previewDepartment = new Department { DepartmentFIS = "CHAN", PrimaryDept = true, Unit = new Unit { FullName = "Advanced Sciences" } }; var previewReference = new Reference { FirstName = "Mike", MiddleName = "H", LastName = "Jones", Title = "Dr." }; var previewApplication = new Application { AssociatedProfile = new Profile { FirstName = "John", MiddleName = "P", LastName = "Smith" } }; previewApplication.AppliedPosition = new Position { Deadline = DateTime.Now.AddDays(20), PositionTitle = "Professor of Technology", HRRep = "Jane Williams", HREmail = "*****@*****.**", Departments = new List <Department> { previewDepartment } }; return(processing.ProcessTemplate(previewReference, previewApplication, templateBody)); }