EmailServicesFunction defines an inbound email service and names the Apex class that processes its messages through apexClass. It controls accepted senders, sending-server authentication, attachment handling, activation, failure actions, and the receiving addresses nested in emailServicesAddresses. The service processes only messages received at one of those configured addresses.
The Apex handler contains the business processing; this metadata controls the entry points and what reaches that code. Deploying the handler alone does not reproduce the service configuration. Also, an address's localPart is only the text before @, not a complete receiving address that can be preserved across orgs.
Key Elements
| Element | What the Element Controls |
|---|---|
apexClass |
Required. Names the ApexClass that processes inbound messages. Changing it changes the handler for every address under the service. |
emailServicesAddresses |
Contains the nested receiving-address definitions. Each address has its own activation, sender restrictions, API name, local part, and processing user. |
Nested address: runAsUser
|
Required. Contains a username, not a user ID. The service assumes this user's permissions when processing messages sent to that address. |
Nested address: localPart
|
Required. Contains only the portion before @. It does not contain Salesforce's generated domain. |
isActive |
Controls activation separately on the service and on each nested address. A service-level value does not establish the activation state of its addresses. |
authorizedSenders |
A comma-separated list of accepted email addresses or domains. Available at both service and address levels. Blank removes only that level's restriction. |
isAuthenticationRequired |
Enables sending-server checks using SPF, SenderId, and DomainKeys. Acceptance requires at least one protocol to pass and none to fail. |
authenticationFailureAction, authorizationFailureAction, functionInactiveAction, overLimitAction
|
Required failure policies. Each accepts Bounce, Discard, Requeue, or UseSystemDefault. They apply to different rejection or deferral conditions. |
attachmentOption |
Required. Accepts All, BinaryOnly, NoContent, None, or TextOnly. Determines whether attachment contents, metadata only, or no attachments reach the handler. |
isTextAttachmentsAsBinary |
When true, supplies text attachments as Messaging.BinaryAttachment with a Blob body instead of Messaging.TextAttachment with a String body. |
isErrorRoutingEnabled, errorRoutingAddress
|
Route processing-error notifications to the chosen address instead of message senders when routing is enabled. |
Behavior and Constraints
Activation and processing identity
Service activation and address activation are separate settings. Do not infer that a nested address is active because the service's isActive is true. functionInactiveAction governs messages received while the service itself is inactive; it is not documented as the policy for an inactive address.
Different addresses under one service can use different runAsUser usernames while sharing the same Apex handler. For cross-org deployment, evaluate each username against the destination users. The address metadata carries the username assignment, not that user's permissions.
Sender restrictions and server authentication
Sender authorization and sending-server authentication are distinct checks. authorizedSenders limits accepted sender addresses or domains. A sender must satisfy any restriction configured at the service level and any restriction configured for the receiving address. Leaving one list blank does not remove a restriction at the other level. Rejection at either level uses the service's authorizationFailureAction.
When isAuthenticationRequired is true, Salesforce checks SPF, SenderId, and DomainKeys, which are protocols for validating the sending server. At least one must pass, and none may fail. Failure of any protocol, or support for none of them, invokes authenticationFailureAction.
isTlsRequired is not currently in use. Its presence or value must not be treated as an enforced Transport Layer Security (TLS) requirement.
Failure policies, notifications, and the shared limit
The four required failure-action settings use the same values:
-
Bounce: Return the message to the sender with an explanation of the rejection. -
Discard: Delete the message without notifying the sender. -
Requeue: Queue the message for processing within the next 24 hours. If it remains unprocessed after 24 hours, return it to the sender with an explanation. -
UseSystemDefault: Use the system default rather than an explicit policy.
overLimitAction applies when the daily processing limit shared by all email services in the org is reached. Salesforce calculates that limit by multiplying the number of user licenses by 1,000. This is not a separate allowance for each service: activity in other services can cause this service to encounter its over-limit policy.
Error-notification routing is separate from these failure policies. When isErrorRoutingEnabled is true, processing-error notifications go to errorRoutingAddress instead of the message senders. This setting controls the notification destination, not which failure action applies.
Attachment acceptance and Apex representation
Interpret attachmentOption together with isTextAttachmentsAsBinary. One controls accepted content; the other changes how text attachments appear to Apex.
-
Noneaccepts the email message but discards its attachments. -
NoContentsupplies attachment metadata, such as filename and MIME type, but sets the attachment body to null. MIME type identifies the attachment's content format. -
Allaccepts all attachment types. -
BinaryOnlyaccepts binary attachments, such as image, audio, application, and video files. -
TextOnlyaccepts text MIME types. It also acceptsapplication/octet-streamattachments ending in.vcfor.vcs, treating them astext/x-vcardandtext/calendar, respectively.
If the handler finds an attachment but cannot read its contents, NoContent is materially different from None: the former preserves metadata with a null body, while the latter discards the attachment.
When isTextAttachmentsAsBinary is true, text attachments arrive as Messaging.BinaryAttachment objects with Apex Blob bodies, not Messaging.TextAttachment objects with Apex String bodies. Handler changes and metadata changes must account for that representation difference. Accepting text attachments does not, by itself, establish which Apex representation the code receives.
Deployment and Retrieval
EmailServicesFunction components use the .xml suffix and reside in the emailservices folder. The type inherits fullName from Metadata. In package.xml, list service members explicitly: this type does not support the wildcard *. See the EmailServicesFunction reference.
The required functionName is the service's API name. It has a 64-character limit and must be unique in the org. It can contain only alphanumeric characters and underscores, must begin with a letter, and cannot contain spaces, end with an underscore, or contain consecutive underscores.
Receiving addresses are nested definitions within EmailServicesFunction, not independent Metadata API deployment members. Each address requires developerName, localPart, and runAsUser:
-
developerNamehas a 25-character limit and must be unique among addresses under the same parent service. It uses alphanumeric characters and underscores, begins with a letter, and cannot end with an underscore or contain consecutive underscores. -
localPartcontains the text before@. Dots are allowed except at the beginning or end, and email addresses are not case-sensitive. -
runAsUsermust be evaluated as a destination-org username, not copied as though it were a portable record ID.
Moving the referenced Apex class alone does not reproduce receiving addresses, their activation states, sender restrictions, or processing identities. Changing apexClass affects all addresses already configured under the service.
Deploying an address definition is different from preserving its complete receiving email address. Salesforce generates a unique domain for each address and exposes it through the read-only runtime field EmailServicesAddress.EmailDomainName. That field is not a nested metadata element to populate. localPart therefore must not be treated as the complete portable receiving address. The runtime address reference describes the separate runtime object.
Community reports distinguish change-set behavior from nested Metadata API deployment and describe address recreation after a Full Copy sandbox refresh. These reports are scoped to the conditions below; neither address deployment nor a refresh should be assumed to preserve the complete receiving address.
Relationships
The service points to one Apex handler and contains receiving-address definitions. Each address's runAsUser associates it with a user by username; this is separate from the metadata reference to the handler class.
References
-
ApexClass:apexClass.
Reported Issues
-
A change set can move the service without its receiving addresses. In a 2021 report, the addresses did not accompany the service in a change set, but deployment succeeded when the address definitions were nested within
EmailServicesFunctionin a Metadata API deployment. The same discussion explains that Salesforce generates each address's domain and exposes it through read-onlyEmailDomainName, so successful deployment does not establish that the full receiving address is portable. Address deployment discussion. - A Full Copy sandbox refresh can require receiving addresses to be recreated. A 2018 discussion reported that existing custom email-service addresses were not retained after refresh and required recreation. Treat this as reported refresh behavior, not a guarantee that deploying the service preserves its addresses. Sandbox refresh discussion.
-
A missing-class error can occur even when
apexClassis populated. In a 2019 report, subscriber-org creation failed with "An Apex Class must be specified when creating an Email Service." andFIELD_INTEGRITY_EXCEPTIONdespite specifying an installed, namespaced, global handler implementingMessaging.InboundEmailHandler. A 2022 follow-up linked a Salesforce Known Issue. Under those conditions, managed-class resolution is a reported possible cause; the discussion does not establish that a workaround remains necessary. Managed-package handler discussion.
Common Questions
Can I deploy EmailServicesAddress separately from EmailServicesFunction?
No. Receiving-address definitions are nested in emailServicesAddresses within EmailServicesFunction. A community report describes successful nested Metadata API deployment after a change set moved the service without its addresses.
Does deploying an email service preserve the same receiving email address?
Do not assume so. localPart contains only the text before @. Salesforce generates the domain and exposes it through the read-only runtime field EmailServicesAddress.EmailDomainName.
Whose permissions does an inbound email service use?
It assumes the permissions of the username in the receiving address's runAsUser. Different addresses under the same service can use different users while sharing one Apex handler.
Why does my Apex email handler receive an attachment with a null body?
attachmentOption set to NoContent supplies attachment metadata but sets the body to null. Also check isTextAttachmentsAsBinary, which changes text attachments from Messaging.TextAttachment with a String body to Messaging.BinaryAttachment with a Blob body.
Why does deployment say an Apex class must be specified when apexClass is set?
A community report describes that error when the specified handler was an installed, namespaced, global class implementing Messaging.InboundEmailHandler. In that situation, managed-class resolution is a reported possible cause, rather than proof that apexClass was omitted.