private static MimePart ConvertAttachmentToMimePart(NotifyMessageAttachment attachment) { try { if (attachment == null || string.IsNullOrEmpty(attachment.FileName) || string.IsNullOrEmpty(attachment.ContentId) || attachment.Content == null) { return(null); } var extension = Path.GetExtension(attachment.FileName); if (string.IsNullOrEmpty(extension)) { return(null); } return(new MimePart("image", extension.TrimStart('.')) { ContentId = attachment.ContentId, Content = new MimeContent(new MemoryStream(attachment.Content)), ContentDisposition = new ContentDisposition(ContentDisposition.Attachment), ContentTransferEncoding = ContentEncoding.Base64, FileName = attachment.FileName }); } catch (Exception) { return(null); } }
private static void AddLetterLogo(NotifyRequest request) { if (TenantExtra.Enterprise || CoreContext.Configuration.CustomMode) { try { var logoData = TenantLogoManager.GetMailLogoDataFromCache(); if (logoData == null) { var logoStream = TenantLogoManager.GetWhitelabelMailLogo(); logoData = ReadStreamToByteArray(logoStream) ?? GetDefaultMailLogo(); if (logoData != null) { TenantLogoManager.InsertMailLogoDataToCache(logoData); } } if (logoData != null) { var attachment = new NotifyMessageAttachment { FileName = "logo.png", Content = ByteString.CopyFrom(logoData), ContentId = MimeUtils.GenerateMessageId() }; request.Arguments.Add(new TagValue(CommonTags.LetterLogo, "cid:" + attachment.ContentId)); request.Arguments.Add(new TagValue(CommonTags.EmbeddedAttachments, new[] { attachment })); return; } } catch (Exception error) { LogManager.GetLogger("ASC").Error(error); } } var logoUrl = CommonLinkUtility.GetFullAbsolutePath(TenantLogoManager.GetLogoDark(true)); request.Arguments.Add(new TagValue(CommonTags.LetterLogo, logoUrl)); }