Ejemplo n.º 1
0
 public ResultModel RemoveFile(Guid id)
 {
     try
     {
         _tempService.RemoveFile(id);
         return(ResultModel.Success);
     }
     catch (Exception e)
     {
         _logService.LogError(e);
         return(new ResultModel(e));
     }
 }
Ejemplo n.º 2
0
 private void AttachFiles(MimeMessage mimeMessage, Guid[] attachIds)
 {
     if (attachIds != null && attachIds.Any())
     {
         try
         {
             foreach (Guid id in attachIds)
             {
                 var file = _tempFilesService.GetFile(id);
                 if (file != null)
                 {
                     var tempFileMemoryStream = new MemoryStream(file.Content);
                     // create an image attachment for the file located at path
                     var attachment = new MimePart(file.MimeType)
                     {
                         Content                 = new MimeContent(tempFileMemoryStream, ContentEncoding.Default),
                         ContentDisposition      = new MimeKit.ContentDisposition(MimeKit.ContentDisposition.Attachment),
                         ContentTransferEncoding = ContentEncoding.Default, // <= was base64
                         FileName                = file.FileName
                     };
                     // now create the multipart/mixed container to hold the message text and the
                     // image attachment
                     var multipart = new Multipart("mixed");
                     multipart.Add(mimeMessage.Body);
                     multipart.Add(attachment);
                     // now set the multipart/mixed as the message body
                     mimeMessage.Body = multipart;
                     _tempFilesService.RemoveFile(id);
                 }
             }
         }
         catch (Exception e)
         {
             _logService.LogError(e);
         }
     }
 }