简体   繁体   中英

How do I access the message body from the Kynetx email endpoint?

I want to extract a URL from an inbound email message and then http:get() the URL. How can I access the message body?

select when mail received from "(.*)@example.com" setting user
pre { /* extract first URL from message */ }
http:get(URL);

So what goes in the PRE block, given the following email message:

From: Example User <user@example.com>
To: x202 Endpoint <a101x202@kynetxapps.net>
Subject: An interesting URL

http://www.example.net

You use the email:parts() method to extract the portions of the email. In a multipart email, you will have both text/html and text/plain parts.

To access the email, you first extract the email (in RFC822 form) from the msg event param, like so:

envelope = event:param("msg");

Then, you can use the parts method to extract a portion. This code example extracts the plain text portion of the email:

textportion = email:parts(envelope,"text/plain").pick("$..text/plain");

Calling email:parts(envelope) without passing a mime filter will return a struct with all the parts of the email.

Once you have the body, you can use textportion.extract(re//) to extract information from the email body.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM