I have raised a question on Drupal Answers related to my feature request.
Basically, it'd be nice to have a possibility to map different emails against different "select" component options (see attachment).
This would be very helpful when you want to send an email notification to different addresses depending on a user selection but you don't want to have an email as a component value(s).

| Comment | File | Size | Author |
|---|---|---|---|
| Clipboard02.jpg | 101.72 KB | Vlad Stratulat |
Comments
Comment #2
Vlad Stratulat commentedComment #3
jrockowitz commentedThis would be great feature to add to the YAML Form module. There are some more important features and issues that need to be addressed first.
There should be some relatively easy way to do this via code. For example, you could use a hidden element or value for the email destination and change the element's via using a hook_form_alter and maybe an '#element_validate' handler.
Maybe someone can post a recipe here.
Comment #4
Vlad Stratulat commentedI was trying to achieve this myself but the only thing I was able to achieve is to add input fields corresponding to the component's options. However, when I was filling the fields with emails and submitting the form, none of them were saved.
I need to learn D8 more (that's what I'm doing at the moment) so that I understand how it's working.
Comment #5
fenstratMoving to Webform queue, see #2827845: [roadmap] YAML Form 8.x-1.x to Webform 8.x-5.x.
Comment #6
gregkeene commentedI had to do this for a project I am currently working on. Following jrockowitz's recommendations above, this is how I did it.
This solution is working great for us.
Comment #7
gregkeene commentedComment #8
jrockowitz commented@see How to programmatically alter destination email address
Comment #9
andypostLooks handlers supports config forms
\Drupal\webform\WebformHandlerInterfacewith\Drupal\Core\Plugin\PluginFormInterface::buildConfigurationForm()methodComment #10
dhansen commentedI think the best way to approach this might be to add conditional logic to handlers/emails in a similar way we have it on fields.
The use case I'm encountering is a contact form where the user can submit sales, support, and billing queries. Not only do the emails go to different places based on the type, but there is a handler that pushes user info into the company's CRM for sales inquiries only. Field-based conditional logic on the handler would make that possible.
Admittedly, this does make the original use case a little more complicated because it would mean a different email/handler for each value. What we'd lose in ease of use, we'd gain in flexibility though sometimes that's not always a great trade.
Comment #11
jrockowitz commentedI think we have to implement the simpler use case and then consider improving conditional logic handling. Right now, we are just using the #state API which is a client side library. We might be able to leverage and/or extend Core's Condition Plugin System.
Comment #12
jrockowitz commentedI needed to start a dedicated ticket with an implementation plan to get this feature rolling.
@see #2854021: Send email based on element options selection
I think conditional routing of emails might be something that the Rules module can handle.
Comment #13
jrockowitz commented@see #2854021: Send email based on element options selection
Comment #15
ashish_6888 commentedIs this possible with Drupal 8. Because it seems like it is Drupal 7.
Comment #16
jrockowitz commented@ashish_6888 This feature is now available with Webfrorm 8.x-5.x.
Comment #17
ashish_6888 commentedI am trying to set the email on the basis of selection of select box value. For ex: select box has two values
1. IT
2. SALES
when i select IT the form should be submitted to ithelpdesk@abc.com and when i select SALES the form should submit to sale_enquiry@xyz.com. I have achieved this using webform in Drupal 7, But i am not able to find any option to achieve the same in Drupal 8.
can you please tell me how i can do this using Drupal 8.
Many Thanks in Advance!!