20 Nov 2009


I am wondering if antyone knows of a way to set up a simple smtp client on an mbed?

It could be used to shoot an email upon some kind of trigger- door open etc..


21 Nov 2009 . Edited: 21 Nov 2009

It seems pretty easy to connect to a SMTP server with a socket connection.

Here is an example for the arduino, should be easy to port over to mbed: You do need to know your mail server address if you want this to work

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte server[] = { 64, 233, 187, 99 }; // Mail server address  MODIFY THIS FOR THE TARGET DOMAIN's MAIL SERVER

Client client(server, 25);

void setup()
 Ethernet.begin(mac, ip);
 if (client.connect()) {
   client.println("EHLO MYSERVER");
   client.println("MAIL FROM:");
   client.println("RCPT TO:");
   client.println("SUBJECT: This is the subject");
   client.println("This is the body.);
   client.println("This is another line of the body.");
 } else {
   Serial.println("connection failed");

void loop()
 if (client.available()) {
   char c =;
 if (!client.connected()) {

Here's the commands you need to send to the server with the socket connection:

But if you have a webserver you could make a PHP script which the mbed would call, and then it sends the email. <- That's what I'm doing

The PHP could be as simple as:

$to = "";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");

21 Nov 2009 . Edited: 21 Nov 2009

Hi Matt,

matt gring wrote:
I am wondering if antyone knows of a way to set up a simple smtp client on an mbed? It could be used to shoot an email upon some kind of trigger- door open etc..

I'd second Vlad's approach of doing an http post to a server that could send the email on your behalf as a first test, but that it because I like http and it keeps things simple :)

The code for a server might look something as simple as (my php is a little rusty!):

<?php mail($_POST["to"], $_POST["subject"], $_POST["body"]); ?>

Then you could just do an HTTPClient post from mbed, and you'd know exactly when the biscuit cupboard door was opened.


21 Nov 2009 . Edited: 21 Nov 2009

Hey Simon,

I like Vlads approach more. If you unable to change the receiver address, therefore nobody can use the script to send spam.


An alternative would be to use an .htaccess file with basic auth and configure the mbed to login.

The client would look like:


HTTPClient client;

int main() {
    client.auth("user","password");, " reminder&body=Door is open");




21 Nov 2009

Thank You all!!

09 Feb 2010 . Edited: 09 Feb 2010

Is there a way to use the command and a php script to send something in the email? say a int? or a string?
Nevermind i just read above. i think i get it :)


Alright, having a little trouble with just the simple php. I can get a script running, much like the Christmas tree example, just using a simple http.get to call the php script. But when i try to use these variables (no authentication), i'm getting nothing, " reminder&body=Door is open");

<?php mail($_POST["to"], $_POST["subject"], $_POST["body"]); ?>

my code is as follows

#include "mbed.h"
#include "HTTPClient.h"

DigitalOut led (LED1);

HTTPClient http;

const char msg[] = " test 2&body=dynamic test";
const char url2[]  = "";

int main() {

//second one, php script dynamic

printf("test 2 starting"); , msg);

        led = !led;

//printf("test 2 finished");

results are


test 2 starting IP:

and a flashing led, no emails