Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
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(() => { GetUploadedFiles(); }); task.Wait(); // 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; this.SendMessage(emailModel); return (object)null; }
private IList<UploadedFile> GetUploadedFiles() { try { 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(); postedFile.InputStream.CopyTo(memoryStream); memoryStream.Position = 0; memoryStream.Seek(0, SeekOrigin.Begin); uploadedFiles.Add( 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; } }
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.