## Create routing rule `client.EmailRouting.Rules.New(ctx, params) (*EmailRoutingRule, error)` **post** `/zones/{zone_id}/email/routing/rules` Rules consist of a set of criteria for matching emails (such as an email being sent to a specific custom email address) plus a set of actions to take on the email (like forwarding it to a specific destination address). ### Parameters - `params RuleNewParams` - `ZoneID param.Field[string]` Path param: Identifier. - `Actions param.Field[[]Action]` Body param: List actions patterns. - `Type ActionType` Type of supported action. - `const ActionTypeDrop ActionType = "drop"` - `const ActionTypeForward ActionType = "forward"` - `const ActionTypeWorker ActionType = "worker"` - `Value []string` - `Matchers param.Field[[]Matcher]` Body param: Matching patterns to forward to your actions. - `Type MatcherType` Type of matcher. - `const MatcherTypeAll MatcherType = "all"` - `const MatcherTypeLiteral MatcherType = "literal"` - `Field MatcherField` Field for type matcher. - `const MatcherFieldTo MatcherField = "to"` - `Value string` Value for matcher. - `Enabled param.Field[RuleNewParamsEnabled]` Body param: Routing rule status. - `const RuleNewParamsEnabledTrue RuleNewParamsEnabled = true` - `const RuleNewParamsEnabledFalse RuleNewParamsEnabled = false` - `Name param.Field[string]` Body param: Routing rule name. - `Priority param.Field[float64]` Body param: Priority of the routing rule. ### Returns - `type EmailRoutingRule struct{…}` - `ID string` Routing rule identifier. - `Actions []Action` List actions patterns. - `Type ActionType` Type of supported action. - `const ActionTypeDrop ActionType = "drop"` - `const ActionTypeForward ActionType = "forward"` - `const ActionTypeWorker ActionType = "worker"` - `Value []string` - `Enabled EmailRoutingRuleEnabled` Routing rule status. - `const EmailRoutingRuleEnabledTrue EmailRoutingRuleEnabled = true` - `const EmailRoutingRuleEnabledFalse EmailRoutingRuleEnabled = false` - `Matchers []Matcher` Matching patterns to forward to your actions. - `Type MatcherType` Type of matcher. - `const MatcherTypeAll MatcherType = "all"` - `const MatcherTypeLiteral MatcherType = "literal"` - `Field MatcherField` Field for type matcher. - `const MatcherFieldTo MatcherField = "to"` - `Value string` Value for matcher. - `Name string` Routing rule name. - `Priority float64` Priority of the routing rule. - `Tag string` Routing rule tag. (Deprecated, replaced by routing rule identifier) ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/email_routing" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) emailRoutingRule, err := client.EmailRouting.Rules.New(context.TODO(), email_routing.RuleNewParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Actions: cloudflare.F([]email_routing.ActionParam{email_routing.ActionParam{ Type: cloudflare.F(email_routing.ActionTypeForward), }}), Matchers: cloudflare.F([]email_routing.MatcherParam{email_routing.MatcherParam{ Type: cloudflare.F(email_routing.MatcherTypeLiteral), }}), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", emailRoutingRule.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "a7e6fb77503c41d8a7f3113c6918f10c", "actions": [ { "type": "forward", "value": [ "destinationaddress@example.net" ] } ], "enabled": true, "matchers": [ { "type": "literal", "field": "to", "value": "test@example.com" } ], "name": "Send to user@example.net rule.", "priority": 0, "tag": "a7e6fb77503c41d8a7f3113c6918f10c" } } ```