Simple solution to send gmail via smtp

Hi, @bko

Thanks your replying.

No. I don't do anything special for the Twitter example, it has connected to internet with same situation of Pushingbox example.

I try this now.

I understood about Gmail encrypted connection which you mentioned.

Thank you.
Daisuke

Hi, @bko

I have tried client.available() and andclient.read() with Pushongbox example.
code is here.

const char server[] = "api.pushingbox.com";
const char url[] = "/pushingbox?devid=myDevid";  //replace with your devid
TCPClient myTCP;
TCPClient client;

void setup() {

}

void loop() {
    delay(10000);
    sendGetRequest(server, url);
    delay(30000); //be nice every 30 seconds
}

void sendGetRequest(const char * server, const char * url)
{
    if (myTCP.connect(server, 80)) {
        myTCP.print("GET ");
        myTCP.print(url);
        myTCP.println(" HTTP/1.0");
        myTCP.println("Connection: close");
        myTCP.print("Host: ");
        myTCP.println(server);
        myTCP.println("Accept: text/html, text/plain");
        myTCP.println();
        myTCP.flush();
        Serial.println("*this is client message**");
        Serial.println(client.available());
        Serial.println(client.read());
    } 
}

Then, Serial says

*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1
*this is client message**
0
-1

What does it mean?

This means the web host has not responded yet or at all. There are 0 bytes and available and in that case, trying the read returns -1 meaning no data.

You don’t need two TCPClient’s so delete TCPClient client;

Try something like this:

...
myTCP.flush();  // start from your current flush() command:
delay(2000);  // just wait 2 sec for an answer for now
unsigned long nbytes = myTCP.available();
while(nbytes--) {
  Serial.print(myTCP.read()); }
Serial.println();
...

Also, you may want to add short delays between some of your TCP commands. We have a development server at work running a really old version of Apache that is cantankerous with rapid-fire TCP commands without short delays between them (10-100 ms).

Hi, @bko

I think something wrong with code just Serial says

this is client message*

const char server[] = "api.pushingbox.com";
const char url[] = "/pushingbox?devid=MyDevid";  //replace with your devid
TCPClient myTCP;

void setup() {

}

void loop() {
    Serial.begin(9600);
    delay(10000);
    sendGetRequest(server, url);
    delay(30000); //be nice every 30 seconds
}

void sendGetRequest(const char * server, const char * url)
{
    if (myTCP.connect(server, 80)) {
        myTCP.print("GET ");
        myTCP.print(url);
        myTCP.println(" HTTP/1.0");
        myTCP.println("Connection: close");
        myTCP.print("Host: ");
        myTCP.println(server);
        myTCP.println("Accept: text/html, text/plain");
        myTCP.println();
        myTCP.flush();
        Serial.println("*this is client message**");
        myTCP.flush();  // start from your current flush() command:
        delay(2000);  // just wait 2 sec for an answer for now
        unsigned long nbytes = myTCP.available();
        while(nbytes--) {
        Serial.print(myTCP.read()); }
        Serial.println();
    } 
} 

I have succeed to send Email with my Sakura domain email service.
I will upload my code to Github later for sharing with everybody :wink:

Just be sure: you are replacing the “MyDevid” with your actual devid which looks like “v0123456789abcd”. You have to get that from the pushing box web site, right?

I ask because this is almost exactly the code I used successfully.

I am glad that sendmail has worked for you on Sakura!

Just be sure: you are replacing the "MyDevid" with your actual devid which looks like "v0123456789abcd". You have to get that from the pushing box web site, right?

Yes, I am sure. I just did copy and paste.

My Code is here!
Sparkcore Door opening notifier with Email

Another question is
How can I connect dry cell battery to the Core? I am afraid it cannot use outlet in some place.

@Daisuke,

you can plug 3.6 to 6.0V to the Vin pin and ground

http://docs.spark.io/images/core-power1.jpg

Just take note that on average the :spark: core using 200-350mA of current and your battery with low mAH is gonna die real fast.

NOTE: DO NOT PLUG IN BOTH USB and Dry cell battery if the dry cell is >5.0V

There’s a diode to for protection the usb but let’s not attempt to do that :smile:

@kennethlimcp
Thank you :wink: