public async Task <EmailMessage> PrepareWelcomeMail(NotificationDto notification) { string notificantEmail = (await _userStorage.FindAsync(u => u.Id == notification.NotificantId)).Email; EmailMessage emailMessage = new EmailMessage(); string mailName = "WelcomeMessage"; MailConfigDto mailConfigDto = await _mailConfig.GetConfig(mailName); SendGridTemplateDto template = await _sendGridService.GetMailTemplate(mailConfigDto.TemplateId); DTOs.Version activeTemplate = template.Versions.FirstOrDefault(v => v.Active == 1); EmailAddress fromAddress = _fromAddress; EmailAddress toAddress = new EmailAddress("", notificantEmail); emailMessage.FromAddresses.Add(fromAddress); emailMessage.ToAddresses.Add(toAddress); emailMessage.Subject = $"{activeTemplate.Subject} {_testEmailIndicator}"; string htmlContent = activeTemplate.HtmlContent.Replace("{{currentYear}}", DateTime.Now.Year.ToString()); string plainTextContent = activeTemplate.PlainContent.Replace("{{currentYear}}", DateTime.Now.Year.ToString()); emailMessage.MailContent.Add("text/html", htmlContent); emailMessage.MailContent.Add("text/plain", plainTextContent); return(emailMessage); }
public async Task <EmailMessage> PrepareInvalidWorkspaceInviteMail(NotificationDto notification) { string notificantEmail = (await _userStorage.FindAsync(u => u.Id == notification.NotificantId)).Email; EmailMessage emailMessage = new EmailMessage(); string mailName = "InvalidWorkspaceInviteMessage"; MailConfigDto mailConfigDto = await _mailConfig.GetConfig(mailName); SendGridTemplateDto template = await _sendGridService.GetMailTemplate(mailConfigDto.TemplateId); DTOs.Version activeTemplate = template.Versions.FirstOrDefault(v => v.Active == 1); EmailAddress fromAddress = _fromAddress; EmailAddress toAddress = new EmailAddress("", notificantEmail); emailMessage.FromAddresses.Add(fromAddress); emailMessage.ToAddresses.Add(toAddress); emailMessage.Subject = $"{activeTemplate.Subject} {_testEmailIndicator}"; ProjectDto project = notification.NotificationObject as ProjectDto; string htmlContent = activeTemplate.HtmlContent .Replace("{{projectName}}", project.Name) .Replace("{{workspaceName}}", project.CommunicationPlatform); string plainTextContent = activeTemplate.PlainContent .Replace("{{projectName}}", project.Name) .Replace("{{workspaceName}}", project.CommunicationPlatform); emailMessage.MailContent.Add("text/html", htmlContent); emailMessage.MailContent.Add("text/plain", plainTextContent); return(emailMessage); }
public async Task <EmailMessage> PrepareInitialFeedbackRequestMail(NotificationDto notification) { UserEntity user = await _userStorage.FindAsync(u => u.Id == notification.NotificantId); string notificantEmail = user.Email; EmailMessage emailMessage = new EmailMessage(); string mailName = "InitialFeedbackRequestMessage"; MailConfigDto mailConfigDto = await _mailConfig.GetConfig(mailName); SendGridTemplateDto template = await _sendGridService.GetMailTemplate(mailConfigDto.TemplateId); DTOs.Version activeTemplate = template.Versions.FirstOrDefault(v => v.Active == 1); EmailAddress fromAddress = _fromAddress; EmailAddress toAddress = new EmailAddress("", notificantEmail); emailMessage.FromAddresses.Add(fromAddress); emailMessage.ToAddresses.Add(toAddress); emailMessage.Subject = $"{activeTemplate.Subject} {_testEmailIndicator}"; string htmlContent = activeTemplate.HtmlContent; string plainTextContent = activeTemplate.PlainContent; emailMessage.MailContent.Add("text/html", htmlContent); emailMessage.MailContent.Add("text/plain", plainTextContent); return(emailMessage); }
private async Task <List <EmailMessage> > PrepareMail() { List <EmailMessage> emailMessages = new List <EmailMessage>(); // Get template content from SendGrid SendGridTemplateDto template = await _sendGridService.GetMailTemplate(_mailConfigDto.TemplateId); // Get recepients and projects List <ProjectEntity> projects = await _projectStorage.FindAsync(); List <UserEntity> users = await _userStorage.FindAsync(); if (projects.Count() == 0 || users.Count() == 0) { return(emailMessages); } foreach (UserEntity user in users) { // Skip if user has no technologies listed if (user.UserTechnologies.Count == 0) { continue; } List <ProjectEntity> matchingProjects = new List <ProjectEntity>(); foreach (ProjectEntity project in projects) { // Skip if project has no technologies listed if (project.ProjectTechnologies.Count == 0) { continue; } IEnumerable <string> userTechnologies = user.UserTechnologies.Select(userTech => userTech.Name); IEnumerable <string> projectTechnologies = project.ProjectTechnologies.Select(projectTech => projectTech.Name); var intersection = userTechnologies.Intersect(projectTechnologies); if (intersection.Count() > 0) { matchingProjects.Add(project); } } List <ProjectEntity> projectRecommendations = SelectNRandomProjects(matchingProjects, _numberOfProjectRecommendations); EmailMessage message = BuildProjectRecommendationsMessage(user, projectRecommendations, template); emailMessages.Add(message); } return(emailMessages); }
private EmailMessage BuildLaunchShowcaseMessage(UserEntity user, SendGridTemplateDto template) { EmailMessage message = new EmailMessage(); EmailAddress toAddress = new EmailAddress("", user.Email); EmailAddress fromAddress = _fromAddress; MailEngine.DTOs.Version templateV1 = template.Versions.First(); message.ToAddresses.Add(toAddress); message.FromAddresses.Add(fromAddress); message.Subject = $"{templateV1.Subject} {_testEmailIndicator}"; string htmlContent = templateV1.HtmlContent.Replace("{{currentYear}}", DateTimeOffset.Now.Year.ToString()); string plainTextContent = templateV1.PlainContent.Replace("{{currentYear}}", DateTimeOffset.Now.Year.ToString()); message.MailContent.Add("text/html", htmlContent); message.MailContent.Add("text/plain", plainTextContent); return(message); }
private async Task <List <EmailMessage> > PrepareMail() { List <EmailMessage> emailMessages = new List <EmailMessage>(); SendGridTemplateDto template = await _sendGridService.GetMailTemplate(_mailConfigDto.TemplateId); // Get recepients and projects List <UserEntity> users = await _userStorage.FindAsync(); if (users.Count() == 0) { return(emailMessages); } foreach (UserEntity user in users) { EmailMessage message = BuildLaunchShowcaseMessage(user, template); emailMessages.Add(message); } return(emailMessages); }
public async Task <EmailMessage> PrepareProjectPostedMail(NotificationDto notification, ProjectDto project) { UserEntity user = await _userStorage.FindAsync(u => u.Id == notification.NotificantId); string notificantEmail = user.Email; EmailMessage emailMessage = new EmailMessage(); string mailName = "ProjectPostedMessage"; MailConfigDto mailConfigDto = await _mailConfig.GetConfig(mailName); SendGridTemplateDto template = await _sendGridService.GetMailTemplate(mailConfigDto.TemplateId); DTOs.Version activeTemplate = template.Versions.FirstOrDefault(v => v.Active == 1); // Get workspace install url string workspaceType = project.CommunicationPlatform; string installUrl = await _workspaceAppService.GetInstallUrl(workspaceType); EmailAddress fromAddress = _fromAddress; EmailAddress toAddress = new EmailAddress("", notificantEmail); emailMessage.FromAddresses.Add(fromAddress); emailMessage.ToAddresses.Add(toAddress); emailMessage.Subject = $"{activeTemplate.Subject} {_testEmailIndicator}"; string htmlContent = activeTemplate.HtmlContent .Replace("{{workspaceType}}", workspaceType) .Replace("{{workspaceAppInstallUrl}}", installUrl); string plainTextContent = activeTemplate.PlainContent .Replace("{{workspaceType}}", workspaceType) .Replace("{{workspaceAppInstallUrl}}", installUrl); emailMessage.MailContent.Add("text/html", htmlContent); emailMessage.MailContent.Add("text/plain", plainTextContent); return(emailMessage); }
public async Task <EmailMessage> PrepareFeedbackMail(NotificationDto notification) { string feedbackContent = notification.Content; EmailMessage emailMessage = new EmailMessage(); string mailName = "FeedbackMessage"; MailConfigDto mailConfigDto = await _mailConfig.GetConfig(mailName); SendGridTemplateDto template = await _sendGridService.GetMailTemplate(mailConfigDto.TemplateId); DTOs.Version activeTemplate = template.Versions.FirstOrDefault(v => v.Active == 1); emailMessage = JsonConvert.DeserializeObject <EmailMessage>(AppSettings.FeedbackRecipients); EmailAddress fromAddress = _fromAddress; emailMessage.FromAddresses.Add(fromAddress); emailMessage.Subject = $"{activeTemplate.Subject} {_testEmailIndicator}"; string htmlContent = activeTemplate.HtmlContent.Replace("{{feedbackMessage}}", feedbackContent); string plainTextContent = activeTemplate.PlainContent.Replace("{{feedbackMessage}}", feedbackContent); emailMessage.MailContent.Add("text/html", htmlContent); emailMessage.MailContent.Add("text/plain", plainTextContent); return(emailMessage); }
public async Task <SendGridTemplateDto> GetMailTemplate(string templateId) { SendGridTemplateDto template = await _http.Get <SendGridTemplateDto>($"{_baseUri}/templates/{templateId}", _headers); return(template); }
private EmailMessage BuildProjectRecommendationsMessage(UserEntity user, List <ProjectEntity> projects, SendGridTemplateDto template) { EmailMessage message = new EmailMessage(); EmailAddress toAddress = new EmailAddress("", user.Email); EmailAddress fromAddress = _fromAddress; MailEngine.DTOs.Version templateV1 = template.Versions.First(); message.ToAddresses.Add(toAddress); message.FromAddresses.Add(fromAddress); message.Subject = $"{templateV1.Subject} {_testEmailIndicator}"; string htmlContent = ReplaceMessageVariables(templateV1.HtmlContent, user, projects); string plainTextContent = ReplaceMessageVariables(templateV1.PlainContent, user, projects); message.MailContent.Add("text/html", htmlContent); message.MailContent.Add("text/plain", plainTextContent); return(message); }