Episerver forms - send files as email attachment


Case: The current actor delivered by episerver for sending emails does not support sending uploaded files as attachments. Intranet applications or applications with access rights cannot use the file link that the current actor sends when sending emails outside the domain or to users with limited access rights.

Fix: The current actor should have a checkbox/toggle for sending the email with uploaded files as attachments, or a field with selected upload files elements.

Current workaround: Currently this can be done with a custom actor, but should be a part of the delivered email actor. Having multiple email actors can be confusing for the editors.

Apr 20, 2017 9:55

For now to attach files, the workaround is to read the input stream directly from this.HttpRequestContext.Files and attach the stream in the mail message.

Here is an idea how I did it:

        public override object Run(object input)
            /* The file uploading might take a while so we have to wait till Epi Forms successfully uploads the files. */
            Task task = Task.Factory.StartNew(() =>

            // This is inherited code of base class
            IEnumerable<EmailTemplateActorModel> emailModel = this.Model as IEnumerable<EmailTemplateActorModel>;
            if (emailModel == null || emailModel.Count<EmailTemplateActorModel>() < 1)
                return (object)null;


            return (object)null;

        private IList<UploadedFile> GetUploadedFiles()
                for (int i = 0; i < this.HttpRequestContext.Files.Count; i++)
                    HttpPostedFileBase postedFile = this.HttpRequestContext.Files[i];
                    postedFile.InputStream.Position = 0;
                    postedFile.InputStream.Seek(0, SeekOrigin.Begin);

                    MemoryStream memoryStream = new MemoryStream();
                    memoryStream.Position = 0;
                    memoryStream.Seek(0, SeekOrigin.Begin);

                        new UploadedFile()
                            Name = postedFile.FileName,
                            Type = System.Web.MimeMapping.GetMimeMapping(postedFile.FileName),
                            InputStream = memoryStream
            catch (Exception ex)
                PostSubmissionActorBase._logger.Error("Failed to get uploaded files: {0}", ex);
            return uploadedFiles;
    public class UploadedFile
        public string Name { get; set; }
        public string Type { get; set; }
        public MemoryStream InputStream { get; set; }

Mar 29, 2018 13:46

+1 -- helps with upholding GDPR

Apr 29, 2019 13:20
This thread is locked and should be used for reference only.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.