({{, (RefLink[MailReceiverFunction, paclet:ref/MailReceiverFunction])[fun] 
represents a mail receiver function that applies fun to any mail message it receives.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[CloudDeploy, paclet:ref/CloudDeploy])[MailReceiverFunction[…]] yields a (RefLink[CloudObject, paclet:ref/CloudObject]) containing metainformation specifying the email address to which mail for the mail receiver should be sent.

For the Wolfram Cloud, the email address is typically of the form receiver+xxxx@wolframcloud.com, where xxxx is a unique ID assigned to each mail receiver.

In (RefLink[MailReceiverFunction, paclet:ref/MailReceiverFunction])[fun], fun[assoc] is evaluated whenever a piece of mail is received. The association assoc is derived from the mail received.

The following basic primary elements are usually present in the association:

Additional possible elements related to senders and recipients include:

Elements related to the message include:

Elements related to attachments include:

Elements related to message identification and threading include:

Elements related to message routing include:

Elements associated with mail headers include:

Elements associated with message origination include:

Special elements of the association include:

(RefLink[MailReceiverFunction, paclet:ref/MailReceiverFunction]) has the following options:

The function fun is evaluated in the environment of the owner of the mail receiver function.

(RefLink[MailReceiverFunction, paclet:ref/MailReceiverFunction])[fun]["string"] decodes the string as a mail message and returns the result of applying fun to the resulting association.

(RefLink[MailReceiverFunction, paclet:ref/MailReceiverFunction])[fun][(RefLink[File, paclet:ref/File])[…]] decodes the contents of a file as a mail message.

The setting for "AttachmentAssociations" is a list giving an association for each attachment. The elements of this association are typically:

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Find the sender from the first message in an MBOX file:

MailReceiverFunction[#From&][File["ExampleData/in.mbox"]]

Deploy a mail receiver that notifies you when a message is received:

CloudDeploy[MailReceiverFunction[SendMail[#From<>" sent your receiver mail about "<>#Subject]&]]

Log the body content of an email in your cloud account:

CloudDeploy[MailReceiverFunction[CloudPut[#Body, "MailLog"]&]]

Send an email to the receiver function and verify the log:

SendMail[<|"To"->"receiver+5i2fllkh@wolframcloud.com","Body"->"Hello There"|>];

CloudGet["MailLog"]

OpenersExampleSection1(Spacer1)Scope  (1)

Get a full message as a (RefLink[Dataset, paclet:ref/Dataset]) from an MBOX file:

Dataset@MailReceiverFunction[#Association&][File["ExampleData/in.mbox"]]

OpenersExampleSection3(Spacer1)Applications  (2)

Create an email account that exports an attachment to the web:

CloudDeploy[MailReceiverFunction[If[Length[#Attachments]>0,CloudExport[First[#Attachments], "PNG","MailAttachment"]]&]]

Send an image to the receiver:

SendMail[<|"To"->"receiver+njSdwTWe@wolframcloud.com","Subject"->"A flower","AttachedExpressions"->ResourceData["Sample Image: Orange Butterfly on a Purple Flower"]|>];

View the exported attachment in a browser:

SystemOpen[CloudObject["MailAttachment"]]

Automatically send a custom receipt confirmation:

CloudDeploy[MailReceiverFunction[SendMail[<|"To"->#ReplyToList,
"Subject"->"I got your message","Body"->"I received your email that started with:\n\t"<>StringTake[#Body,UpTo[100]]|>]&]]

A response will automatically be computed and sent:

SendMail[<|"To"->"receiver+njSKTcux@wolframcloud.com","Subject"->"An important message","Body"->"This is very urgent! Please let me know that you have received this message. We must remember to record tonight's episode of Jeopardy! Alex Trebek is captivating."|>];

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

(RefLink[ChannelReceiverFunction, paclet:ref/ChannelReceiverFunction]) works analogously to (RefLink[MailReceiverFunction, paclet:ref/MailReceiverFunction]) on channel broker messages:

CloudDeploy[ChannelReceiverFunction[CloudPut[#Message, "ChannelLog"]&]]

Send a message to the associated channel and verify the log:

ChannelSend[ChannelObject[%],"channel message"]

CloudGet["ChannelLog"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[MailResponseFunction, paclet:ref/MailResponseFunction])  ▪  (RefLink[ReturnReceiptFunction, paclet:ref/ReturnReceiptFunction])  ▪  (RefLink[APIFunction, paclet:ref/APIFunction])  ▪  (RefLink[DatabinAdd, paclet:ref/DatabinAdd])  ▪  (RefLink[SendMail, paclet:ref/SendMail])  ▪  (RefLink[FormFunction, paclet:ref/FormFunction])  ▪  (RefLink[Import, paclet:ref/Import])  ▪  (RefLink[ChannelReceiverFunction, paclet:ref/ChannelReceiverFunction])  ▪  (RefLink[MailServerConnect, paclet:ref/MailServerConnect])  ▪  (RefLink[MailExecute, paclet:ref/MailExecute])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Automatic Mail Processing, paclet:guide/AutomaticMailProcessing])}, {▪(RefLinkPlain[Mail, Messages, Etc., paclet:guide/MailMessagesEtc])}, {▪(RefLinkPlain[Handling Live Mailboxes, paclet:guide/HandlingLiveMailboxes])}, {▪(RefLinkPlain[Cloud Functions & Deployment, paclet:guide/CloudFunctionsAndDeployment])}})}})