How we can send email with attached file, while clicking form submit button?
We are currently using Sitecore 9 Update 2 with SXA 1.7.2.
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communityHow we can send email with attached file, while clicking form submit button?
We are currently using Sitecore 9 Update 2 with SXA 1.7.2.
As an alternative, you can create a custom action "send email" based on: Send-E-mail-Action-to-Sitecore-9-Forms, add to action's editor dialog/view model link to media item. And when on action executing add to mail attachments linked media item.
There is no functionality like that in your version of Sitecore, neither it is in latest Sitecore 9.1.
You have two options:
Use code from Sitecore Forms Extensions github repository https://github.com/bartverdonck/Sitecore-Forms-Extensions and specifically this part -> https://github.com/bartverdonck/Sitecore-Forms-Extensions/tree/master/src/Feature/FormsExtensions/code/Fields/FileUpload.
It should have really simple model:
using System;
using System.Globalization;
using System.Web;
using Feature.FormsExtensions.Business.FileUpload;
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.ExperienceForms.Mvc.Models.Validation;
namespace Feature.FormsExtensions.Fields.FileUpload
{
[Serializable]
public class FileUploadModel : ValueNotValidatedInputViewModel<IStoredFile>
{
[NonSerialized]
private HttpPostedFileBase file;
private const string AllowedContentTypesParam = "Allowed Content Types";
private const string MaxFileSizeParam = "Max File Size";
[DynamicRequired]
[DynamicValidation]
public virtual HttpPostedFileBase File
{
get => file;
set => file = value;
}
public string AllowedContentTypes { get; set; }
public int MaxFileSize { get; set; }
protected override void InitItemProperties(Item item)
{
base.InitItemProperties(item);
AllowedContentTypes = StringUtil.GetString(item.Fields[AllowedContentTypesParam]);
MaxFileSize = MainUtil.GetInt(item.Fields[MaxFileSizeParam]?.Value, 0);
}
protected override void UpdateItemFields(Item item)
{
base.UpdateItemFields(item);
item.Fields[AllowedContentTypesParam]?.SetValue(AllowedContentTypes, true);
item.Fields[MaxFileSizeParam]?.SetValue(MaxFileSize.ToString(CultureInfo.InvariantCulture),true);
}
}
}