Esempio n. 1
0
        protected virtual void CreateAttachments(QueuedEmail queuedEmail, MessageContext messageContext)
        {
            var messageTemplate = messageContext.MessageTemplate;
            var languageId      = messageContext.Language.Id;

            // create attachments if any
            var fileIds = (new int?[]
            {
                messageTemplate.GetLocalized(x => x.Attachment1FileId, languageId),
                messageTemplate.GetLocalized(x => x.Attachment2FileId, languageId),
                messageTemplate.GetLocalized(x => x.Attachment3FileId, languageId)
            })
                          .Where(x => x.HasValue)
                          .Select(x => x.Value)
                          .ToArray();

            if (fileIds.Any())
            {
                var files = _downloadService.GetDownloadsByIds(fileIds);
                foreach (var file in files)
                {
                    queuedEmail.Attachments.Add(new QueuedEmailAttachment
                    {
                        StorageLocation = EmailAttachmentStorageLocation.FileReference,
                        FileId          = file.Id,
                        Name            = (file.Filename.NullEmpty() ?? file.Id.ToString()) + file.Extension.EmptyNull(),
                        MimeType        = file.ContentType.NullEmpty() ?? "application/octet-stream"
                    });
                }
            }
        }