I want to control the level my water tank with a esp8266 and Thingspeak. I can see the level in Thingspeak. This is working. Now I want to send 2 emails : One daily email with the actual level Alarm email when level is below a setpoint. How can I incorporate the value from a channel in the email ? What I have now for the daily email , but with errors : alert_body = 'huidig peil regenput'; channelID = ..........; % Provide the ThingSpeak alerts API key. All alerts API keys start with TAK. alertApiKey = 'TAK...............'; % Set the address for the HTTTP call alertUrl="https://api.thingspeak.com/alerts/send"; % webwrite uses weboptions to add required headers. Alerts needs a ThingSpeak-Alerts-API-Key header. options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", alertApiKey ]); % Set the email subject. alertSubject = sprintf("Niveau regenput " ); % Read the recent data. peil = thingSpeakRead(channelID,'Fields',1); % Check to make sure the data was read correctly from the channel. % Set the outgoing message webwrite(alertUrl , "body", alertBody, "subject", alertSubject,'Fields',peil); % Catch errors so the MATLAB code does not disable a TimeControl if it fails try webwrite(alertUrl , "body", alert_body, "subject", alertSubject, options); catch someException fprintf("Failed to send alert: %s\n", someException.message); end The errors I receive : Unrecognized function or variable 'alert_Body'. Error in Read Channel to Trigger Email 1 (line 24) webwrite(alertUrl , "body", alert_Body, "subject", alertSubject,"Fields",peil); Manny thanks in advance Send email with the value of a channel MATLAB is case sensitive. alert_body is not equal to alert_Body Be careful with daily emails, you are limited to 800 yearly alert emails. (but there are enough for one per day or more) Your code example shows how to put a channel value in the email. peil = thingSpeakRead(channelID,'Fields',1); % Check to make sure the data was read correctly from the channel. % Set the outgoing message webwrite(alertUrl , "body", alertBody, "subject", alertSubject,'Fields',peil); This will make the subject equal to the value from field 1 Hi Christopher, I did the notification and don't receive no errors anymore. Unfortunately I also don't receive the emails in my mailbox. % webwrite uses weboptions to add required headers. Alerts needs a ThingSpeak-Alerts-API-Key header. options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", alertApiKey ]); % Set the email subject. alertSubject = sprintf("Niveau regenput " ); % Read the recent data. peil = thingSpeakRead(channelID,'Fields',1); % Set the outgoing message try webwrite(alertUrl , "body", alertBody, "subject", alertSubject,'Fields',peil); end Check your junk folder and make sure you arent blocking thingspeak.com at your email server. You can also take the try ..end.. syntax off, and remove the semicolon on the webwrite line to test and make sure the command was sent. What do you mean with junk folder ? When I do save and run I receive 2 messages. MATLAB code ran successfully. Failed to send alert: The server returned the status 401 with message "" in response to the request to URL https://api.thingspeak.com/alerts/send. 401 means unauthorized. Check your alerts api key. By junk folder i menat for email, but its clear its not sending. I copy past het API key again but no result. does the api key begin with TAK? yes. I use the alertapikey alertApiKey = 'TAKMAxjn5Ad1TrzrNWH'; I also renewed already the key, but no result. You are forgetting the options when you webwrite. Thats why its 401 unauthorized. No key included with the requiest. webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options); webwrite(alertUrl , "body", alertBody, "subject", alertSubject, peil, options); doesn't work webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options); Was sending an email once, but without the value of channel 1 Afterwards I received the message when I run the app : "Failed to send alert: Each postName must be given a corresponding postValue." where can I find the documentation about sending information by email ? All the examples I can find only describe the software for the arduino or esp8266/32 https://www.mathworks.com/help/thingspeak/alerts-api.html and https://www.mathworks.com/help/thingspeak/sendalert.html I reccomend you start with the example code and try to modify it one part at a a time. This example is independant of the devece. I would start here. https://www.mathworks.com/help/thingspeak/analyze-channel-data-to-send-email.html My soil moisture cannel doesnt have good data anymore, but you can tie it to the traffic 38629 or weather 12397 channels at ThingSpeak for testing. In the example, you can add the moisture data to the alert body variable to bet information sent to you. I started from these exemples and could send emails but after I tried to include to value of channel 1, I don't receive emails anymore and receive error messages when I run the timecontrol app without to make any changes. I still struggle with my originale question how to include the value of a channel in the body of the email. Christopher, I followed this example. You only send an email with text. I want to send text + the last value from channel 1. What is working for the moment: 1. sending text with : alertBody = 'huidig peil regenput :'; 2. Sending value of channel 1 : alertBody = thingSpeakRead(channelID,'Field',1); What is not working is the combination of both. It must be something like this, but this syntax is not accepted : alertBody = ('huidig peil regenput :' ,thingSpeakRead(channelID,'Field',1)); try seperating the actions. bob = thingSpeakRead(channelID,'Field',1)); % assumes data is numeric, otherwise use 'outputformat','timetable' alertBody = "The value of my field is " + bob; email timecontrol