diff --git a/api/src/Sozsoft.Platform.Application/Public/PublicAppService.cs b/api/src/Sozsoft.Platform.Application/Public/PublicAppService.cs index 0b7d19d7..d0e340ea 100644 --- a/api/src/Sozsoft.Platform.Application/Public/PublicAppService.cs +++ b/api/src/Sozsoft.Platform.Application/Public/PublicAppService.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Sozsoft.Platform.Entities; using Volo.Abp.Domain.Repositories; -using System.Text; using Sozsoft.Platform.Data.Seeds; using Sozsoft.Sender.Mail; using Volo.Abp.Settings; @@ -318,26 +317,181 @@ public class PublicAppService : PlatformAppService var demo = ObjectMapper.Map(input); await _demoRepository.InsertAsync(demo); - var bodyBuilder = new StringBuilder(); - bodyBuilder.AppendLine($"Şirket: {input.OrganizationName}"); - bodyBuilder.AppendLine($"Ad Soyad: {input.Name}"); - bodyBuilder.AppendLine($"E-Posta: {input.Email}"); - bodyBuilder.AppendLine($"Telefon: {input.PhoneNumber}"); - bodyBuilder.AppendLine($"Adres: {input.Address}"); - bodyBuilder.AppendLine($"Şube Sayısı: {input.NumberOfBranches}"); - bodyBuilder.AppendLine($"Kullanıcı Sayısı: {input.NumberOfUsers}"); - bodyBuilder.AppendLine($"Mesaj: {input.Message}"); + await SendDemoCreatedEmailsAsync(input); + } - var SenderName = await _settingProvider.GetOrNullAsync(SeedConsts.AbpSettings.Mailing.Default.DefaultFromDisplayName); - var SenderEmailAddress = await _settingProvider.GetOrNullAsync(SeedConsts.AbpSettings.Mailing.Default.DefaultFromAddress); + private async Task SendDemoCreatedEmailsAsync(DemoDto input) + { + // Demo talebi bildirimleri, uye bildirim ayarindaki adreslere gonderilir. + var recipients = ParseRecipients( + await _settingProvider.GetOrNullAsync(PlatformConsts.AbpSettings.SiteManagement.General.NewMemberNotificationEmails)); - await _emailSender.QueueEmailAsync( - SenderEmailAddress ?? string.Empty, - new KeyValuePair(SenderName ?? string.Empty, SenderEmailAddress ?? string.Empty), - null, - bodyBuilder.ToString(), - subject: PlatformConsts.AppName + " : Demo Talebi"); + if (recipients.Count == 0) + { + Logger.LogWarning( + "Demo request email was not sent: {Setting} setting is empty.", + PlatformConsts.AbpSettings.SiteManagement.General.NewMemberNotificationEmails); + return; + } + + var senderName = await _settingProvider.GetOrNullAsync(SeedConsts.AbpSettings.Mailing.Default.DefaultFromDisplayName); + var senderEmail = await _settingProvider.GetOrNullAsync(SeedConsts.AbpSettings.Mailing.Default.DefaultFromAddress); + KeyValuePair? sender = null; + if (!senderEmail.IsNullOrWhiteSpace()) + { + sender = new KeyValuePair(senderName ?? string.Empty, senderEmail); + } + + var body = BuildDemoEmailBody(input); + var subject = $"{PlatformConsts.AppName} : {Translate("App.PublicDemo.MailTitle")}"; + + foreach (var recipient in recipients) + { + try + { + await _emailSender.SendEmailAsync( + recipient, + sender, + new { }, + body, + subject, + null, + true); + } + catch (Exception ex) + { + Logger.LogError(ex, "Demo request email could not be sent to {Recipient}", recipient); + } + } + } + + private string BuildDemoEmailBody(DemoDto input) + { + string Row(string label, string value, bool striped) => $@" + + {Html(label)} + {Html(value)} + "; + + var contactRows = string.Concat( + Row(Translate("App.PublicCommon.FullName"), input.Name, true), + Row(Translate("App.Listform.ListformField.Email"), input.Email, false), + Row(Translate("Abp.Identity.User.UserInformation.PhoneNumber"), FormatPhoneNumber(input.PhoneNumber), true)); + + var companyRows = string.Concat( + Row(Translate("App.Platform.Company"), input.OrganizationName, true), + Row(Translate("App.PublicCommon.BranchCount"), input.NumberOfBranches.ToString(), false), + Row(Translate("App.PublicCommon.UserCount"), input.NumberOfUsers.ToString(), true), + Row(Translate("App.Listform.ListformField.Address"), input.Address, false)); + + return $@" + + + + + + + + +
+ {Html(Translate("App.PublicDemo.MailIntro"))} +
+ + + + +
+ + + + + + + + +
+ + + + + + +
+ + + + +
+
+ + + + + + + +
{Html(Translate("App.PublicDemo.MailTitle"))}
{Html(Translate("App.PublicDemo.MailIntro"))}
+
+ + + + + + + +
Demo
{FormatDate(Clock.Now)}
+
+
+ + + + + +
+ + + + +
+ + + + {contactRows} +
{Html(Translate("App.PublicDemo.MailContactInfo"))}
+
+
+ + + + +
+ + + + {companyRows} +
{Html(Translate("App.PublicDemo.MailCompanyInfo"))}
+
+
+ + + + + +
+ + + + + + + +
{Html(Translate("App.Listform.ListformField.Message"))}
{Html(input.Message)}
+
+
+
+ +"; } public async Task GetPostListAsync(GetBlogPostsInput input) @@ -585,13 +739,7 @@ public class PublicAppService : PlatformAppService } var notificationEmails = await _settingProvider.GetOrNullAsync("App.SiteManagement.General.NewTenantNotificationEmails"); - if (!notificationEmails.IsNullOrWhiteSpace()) - { - recipients.AddRange(notificationEmails - .Split(new[] { ',', ';', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries) - .Select(email => email.Trim()) - .Where(email => !email.IsNullOrWhiteSpace())); - } + recipients.AddRange(ParseRecipients(notificationEmails)); recipients = recipients .Distinct(StringComparer.OrdinalIgnoreCase) @@ -876,6 +1024,24 @@ public class PublicAppService : PlatformAppService return string.Format(new System.Globalization.CultureInfo("tr-TR"), "{0:C2}", value); } + /// + /// Virgul, noktali virgul veya satir sonu ile ayrilmis e-posta ayar degerini listeye cevirir. + /// + private static List ParseRecipients(string? value) + { + if (value.IsNullOrWhiteSpace()) + { + return []; + } + + return value! + .Split([',', ';', '\n', '\r'], StringSplitOptions.RemoveEmptyEntries) + .Select(email => email.Trim()) + .Where(email => !email.IsNullOrWhiteSpace()) + .Distinct(StringComparer.OrdinalIgnoreCase) + .ToList(); + } + private static string Html(string value) { return WebUtility.HtmlEncode(value ?? string.Empty); diff --git a/api/src/Sozsoft.Platform.DbMigrator/Migrations/LanguagesData.json b/api/src/Sozsoft.Platform.DbMigrator/Migrations/LanguagesData.json index e9f09aee..3e3fcf93 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Migrations/LanguagesData.json +++ b/api/src/Sozsoft.Platform.DbMigrator/Migrations/LanguagesData.json @@ -25625,6 +25625,48 @@ "key": "App.ForumDashboard.NewCategoryCreated", "en": "New category created", "tr": "Yeni kategori oluşturuldu" + }, + { + "resourceName": "Platform", + "key": "App.Validation.Required", + "en": "This field is required.", + "tr": "Bu alan zorunludur." + }, + { + "resourceName": "Platform", + "key": "App.Validation.InvalidEmail", + "en": "Please enter a valid email address.", + "tr": "Geçerli bir e-posta adresi giriniz." + }, + { + "resourceName": "Platform", + "key": "App.Errors.ServerUnreachable", + "en": "The server could not be reached. Please try again later.", + "tr": "Sunucuya ulaşılamadı. Lütfen daha sonra tekrar deneyin." + }, + { + "resourceName": "Platform", + "key": "App.PublicDemo.MailTitle", + "en": "New Demo Request", + "tr": "Yeni Demo Talebi" + }, + { + "resourceName": "Platform", + "key": "App.PublicDemo.MailIntro", + "en": "A new demo request has been submitted through the website.", + "tr": "Web sitesi üzerinden yeni bir demo talebi oluşturuldu." + }, + { + "resourceName": "Platform", + "key": "App.PublicDemo.MailContactInfo", + "en": "Contact Information", + "tr": "İletişim Bilgileri" + }, + { + "resourceName": "Platform", + "key": "App.PublicDemo.MailCompanyInfo", + "en": "Company Information", + "tr": "Firma Bilgileri" } ] }