Try our conversational search powered by Generative AI!

Change XForm From Address from code MVC


I am some troubles trying to change the from address on an xformpostedData object.  My action is XFormPost(XformPostedData xformPostedData)  and inside, i see that xformposteddata has a SelectedSubmit object but all the values are readonly.  This object has a Sender which is readonly as well.  Has anyone had a simliar experiance and/or a resolution to set this.  Thanks in advance.

Mar 14, 2014 15:47

Just an idea, haven't tested:

protected override bool ProcessXFormAction(Controller controller, XFormPostedData xformPostedData)
    var copy = new NameValueCollection(controller.Request.Form);
    copy["from"] = "new sender";

    // rest of body


Edited, Mar 16, 2014 19:58

Hi  Joshua,

any updates about this issue? I have the same problem and I haven't manage to figure out how to do it.


Apr 08, 2015 15:29

Seems like code fragment above is not working :)

Apr 08, 2015 21:49

Nope, I already tried that, it doesn't seems to work.

Aparently, everyting that is on SelectedSubmit object is read only. Would that be other way to change the sender before posting the form?


Apr 08, 2015 21:56

One hacky workaround would be to change "from=" parameter in submit action button in the form on client-side. As it turns out after model binder XFormPostedData object is readonly.

Edited, Apr 09, 2015 10:53

Thanks Valdis for the reply.

Since the "from=" parameter cannot be change, do you know if is there any posibility to add to the form another parameter like "Reply To" and not to try to hack the "from=" parameter.

It will be very usefull for me !

Thanks again!

Apr 09, 2015 11:07

Looking at the model binder don't think it will be available for you in action (will be ignored by xform fragment parser).

Apr 09, 2015 11:13

Well, if at this point is not possible to add/update properties for the SelectedSubmit object, is there any other way to customize the form.

What I have, is a very basic form with an input field for customer email and a submit button that saves into db and sends email, witch is working now, but I want in that email to have the "Reply To" the email that customer inserts into that input field.

Do you know if that would be possible?


Apr 09, 2015 11:22

Hi, Axy,

Can you clarify a bit "I want in that email to have the "Reply To" the email that customer inserts into that input field.", it's a bit strangly formed sentence, so I am not entirely sure what you want to do?

What you could do is not use the XForm email sending. Instead, just save to the DB and put the rest of the properties that are normally on the XForm (such as sender and recipient, etc) on a block which contains the XForm (or page) and then do whatever you want on submitted action. // That is, if I understood your requirements :)



Apr 09, 2015 16:49

Hi Marija,

well sorry for the wierd explanation of the situation.

The thing is that I have a simple form in a episerver block and that simple form has a input, where customer can insert his email address called "Customer Email", and a submit button that saves informations into DB and sends an email.

Now according to the form basic functionality, the sender and the receiver for that email are seted from the "Properties for button" when editing the form. What I want is to add the email address that customer inserts in the "Customer Email" input field to the sending email functionality as a "Reply to". I hope it's more clear now.

I'm not sure if something like that is handled by the xforms, as far as I saw it doesn't, but would that be any workaround for that? Or should I consider not to use xforms for that...?


Apr 10, 2015 10:59

I guess, if form shouldn't be modifed by editors - fastest workaround would be to implement just pure simple form. If editors are modifying form - you could handle sending XForm as email manually then.

Apr 10, 2015 11:11

Hi Axy, 

Were you able to find a solution to this? I need to intercept the form-sending and update the recipient email address before proceeding.

I am hoping you didn't end up developing the form outside XForms.



Jul 28, 2015 9:10


I didn't manage to figure it out, so I end up developing a custom form without XForms.

If you find something, can you please can you share some ideas here..? I'm still curous if it's possible.


Axi :)

Jul 28, 2015 14:58

I don't think you can switch out the recepient of the build in XForm send email functionality. But instead you can set the form to not send any emails and only save the data to the database. Then do this:

By intercepting the after post event you can code your own send Email functionality that can take whatever field value from the posted xform, e.g. the UsersEmail field.



Jul 28, 2015 19:42

I agreed with @Toni and in our implementation, we leave user free to create/edit form with whatever action on submit. Hooked up to XFormActionHelper.AfterSubmitPostedData and send email with your template and recepient

Jul 29, 2015 10:56

Hi everyone, 

I was able to intercept the form sending by registering a handler to the event BeforeSubmitPostedData in the global.asax.

XFormActionHelper.BeforeSubmitPostedData += FormBlockController.BeforeSubmitPostedData;

And then inside the BeforeSubmitPostedData method, I had to do something like:

// Change MailFrom property
e.FormData.MailFrom = formValues.Get("EmailAddressFrom");

// Change MailTo property
e.FormData.MailTo = formValues.Get("EmailAddressTo");

However, the message body of the email could not be updated programmatically (there is no way currently as per EPiServer 8 documentation).

Our client requires a specific email body format, so I ended up removing the sending of email from the ChannelOptions and used SmtpClient to do the message sending.

Works perfectly now. Thanks for everyone's input!


Edited, Jul 29, 2015 13:39

Cool, looks nice.

Thanks for sharing :D

Axi :)

Jul 29, 2015 21:02
* 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.