diff --git a/AsbCloudInfrastructure/Services/Email/BaseFactory.cs b/AsbCloudInfrastructure/Services/Email/BaseFactory.cs index 4e6d3084..8e44725f 100644 --- a/AsbCloudInfrastructure/Services/Email/BaseFactory.cs +++ b/AsbCloudInfrastructure/Services/Email/BaseFactory.cs @@ -22,16 +22,23 @@ namespace AsbCloudInfrastructure.Services.Email supportMail = configuration.GetValue("email:supportMail", "support@digitaldrilling.ru"); } - public static string GetImageBase64(string resourceFileName) + public static string GetOrEmptyImageBase64(string resourceFileName) { if (string.IsNullOrEmpty(resourceFileName)) throw new ArgumentInvalidException("ResourceFileName doesn`t exist", nameof(resourceFileName)); var baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? string.Empty; - var resoursesDir = "Res"; + var resourcesDir = "Res"; + + var logoFilePath = Path.Combine(baseDir, resourcesDir, resourceFileName); + + if (!File.Exists(logoFilePath)) + { + System.Diagnostics.Trace.TraceWarning($"GetOrEmptyImageBase64(). File {logoFilePath} not found."); + return string.Empty; + } - var logoFilePath = Path.Combine(baseDir, resoursesDir, resourceFileName); var imageBytes = File.ReadAllBytes(logoFilePath); var format = Path.GetExtension(resourceFileName).Trim('.'); return "data:image/" + format + ";base64," + Convert.ToBase64String(imageBytes); @@ -42,7 +49,7 @@ namespace AsbCloudInfrastructure.Services.Email public string MakeSignatue() { - var logo = GetImageBase64("logo_32.png"); + var logo = GetOrEmptyImageBase64("logo_32.png"); var sign = $"

---

" + $"{companyName}
" + $"Это письмо сформировано автоматически.
" +