google's smtp says i'm spamming

Hello,

i tried the email client by SurferTim and got at the second attempt Our system has detected an unusual rate of unsolicited mail originating from your IP address

I am trying to send emails to myself upon arduino detecting an anomaly while i'm out

This is not an arduino issue but yet if someone could guide me that'd be grate

Many thnaks in advance

Guy

You can only send a couple every couple hours then you're cut off. Then you must wait a couple hours.

I use the smtp server from my internet provider. That accepts normal flat non-encrypted email. Before using my sketch, I checked it by typing commands in telnet.
The email sketch needs the right settings: the smtp servier, your own ip, email to and email from. Did you get them all right ?

ok, i tried with smtp2go and got three emails delivered in a row but i don't know how to post the code in the small window :slight_smile:

That is the sketch between "Code Tags".
It is explained at item number 7 on this page : forum.arduino.cc/index.php/topic,148850.0.html

It doesn't matter. If you send more than a few within a short period of time, the gmail email server will cut off your attempts for a while, usually a couple hours. SMTP2GO will take them, but they won't get forwarded to gmail for a while. The gmail server did the same to me with my electronics student i used to tutor. My email server would take them, but wouldn't be able to deliver them to the gmail server for a couple hours.

here is what i understand: gmail server is suspicious because i don’t authenticate. I do not authenticate because i won’t send my gmail account password on un-encrypted line. line is not encrypted because arduino (at least the simple boards) does not support it. SMTP2GO does forward my stuff because i do authenticate and i do authenticate on unsecured line because it’s not such a big deal. Now the code is essentially that of SurferTim from here. Few lines are taken from here originally from Nicolaj Joergensen in this page. Changes from original code marked with asterisks. Dingi, my cat, has no gmail account (he’s on yahoo) so that the address (and authentication username) in the code is not his nor is the public ip there our’s. Base 64 encoding thanks to motobit

/

*
   Email client sketch for IDE v1.0.1 and w5100/w5200
   Posted December 2012 by SurferTim
*/

#include <SPI.h>
#include <Ethernet.h>

// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };  
// change network settings to yours
IPAddress ip( 192, 168, 2, 225 );    
IPAddress gateway( 192, 168, 2, 1 );
IPAddress subnet( 255, 255, 255, 0 );

// change server to your email server ip or domain
// IPAddress server( 1, 2, 3, 4 );
char server[] = "smtpcorp.com";
int port=2525;

EthernetClient client;

void setup()
{
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac, ip, gateway, gateway, subnet); 
  delay(2000);
  Serial.println(F("Ready. Press 'e' to send."));
}

void loop()
{
  byte inChar;

  inChar = Serial.read();

  if(inChar == 'e')
  {
      if(sendEmail()) Serial.println(F("Email sent"));
      else Serial.println(F("Email failed"));
  }
}

byte sendEmail()
{
  byte thisByte = 0;
  byte respCode;

  if(client.connect(server,port) == 1) {
    Serial.println(F("connected"));
  } else {
    Serial.println(F("connection failed"));
    return 0;
  }

  if(!eRcv()) return 0;
  Serial.println(F("Sending helo"));

// change to your public ip
//***************modified/added lines
  client.println(F("ehlo 18.57.201.4"));

//auth
  client.println("AUTH LOGIN");                     
  client.println("ZGluZ2lAZ21haWwuY29t");                    
  client.println("bWlhb3U=");
//******************************
  if(!eRcv()) return 0;
  Serial.println(F("Sending From"));

// change to your email address (sender)
  client.println(F("MAIL From: <dingi@gmail.com>"));

  if(!eRcv()) return 0;

// change to recipient address
  Serial.println(F("Sending To"));
  client.println(F("RCPT To: <dingi@gmail.com>"));

  if(!eRcv()) return 0;

  Serial.println(F("Sending DATA"));
  client.println(F("DATA"));

  if(!eRcv()) return 0;

  Serial.println(F("Sending email"));

// change to recipient address
  client.println(F("To: dingi <dingi@gmail.com>"));

// change to your address
  client.println(F("From: dingi <dingi@gmail.com>"));

  client.println(F("Subject: Coucou d'Arduino\r\n"));

  client.println(F("Un petit bonjour de la petite carte de Guy"));

  client.println(F("."));

  if(!eRcv()) return 0;

  Serial.println(F("Sending QUIT"));
  client.println(F("QUIT"));

  if(!eRcv()) return 0;

  client.stop();

  Serial.println(F("disconnected"));

  return 1;
}

byte eRcv()
{
  byte respCode;
  byte thisByte;
  int loopCount = 0;

  while(!client.available()) {
    delay(1);
    loopCount++;

    // if nothing received for 10 seconds, timeout
    if(loopCount > 10000) {
      client.stop();
      Serial.println(F("\r\nTimeout"));
      return 0;
    }
  }

  respCode = client.peek();

  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);
  }

  if(respCode >= '4')
  {
    efail();
    return 0;  
  }

  return 1;
}


void efail()
{
  byte thisByte = 0;
  int loopCount = 0;

  client.println(F("QUIT"));

  while(!client.available()) {
    delay(1);
    loopCount++;

    // if nothing received for 10 seconds, timeout
    if(loopCount > 10000) {
      client.stop();
      Serial.println(F("\r\nTimeout"));
      return;
    }
  }

  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);
  }

  client.stop();

  Serial.println(F("disconnected"));
}

Good job.
I did try using the the base64 in the past, but not like this.
Could you do base64 in the Arduino ? :stuck_out_tongue: Which code would be the base64 for email ? :confused:

Just a minute ago, I changed the code of my email client.
I had too many "EthernetClient client;" in my Mega board + Ethernet Shield.
So I removed the global one, and created "EthernetClient eClient;" inside sendEmail().
The eRcv() and eFail() have now a parameter of "EthernetClient *".

SMTP2GO's email server does not authenticate with the google email server either. My email code sends email like email servers send to each other.

I undersrand that smtp2go is whitelisted on Google server whereas my humble person’ip is not (unless I authenticate)

Does it refuse email from your Arduino immediately? Or after a few sends? If it refuses it immediately, then it isn't exactly that SMPT2GO's email server is whitelisted, but your residential IP is blacklisted.

This is from my email sender code in the playground:

Many email servers will not accept email from a non-commercial, dhcp-issued ip address. If that is the case, the server will send an error with a statement to that fact in the error message.

To your question, it rejected the 2nd time.

Aren't we saying the same thing? I prefers the whitelist because it makes a shorter one :wink: in any case, going through a commercial server like smpt2go is a good solution, especially (as far as arduino) since it requires no ssl. I am sure I can send as many mails as I whish directly to Google's server if I authenticate.

If it takes one email, but refuses the second email, then it isn't that you are blacklisted.

Google's email server will not take multiple sends from the same IP to the same email address one after the other. It has a time limit on those. Last I checked it was three emails within two hours, at least from my email server.

And you may be correct now. Maybe Google has changed the policy on multiple emails from a registered email server. I wouldn't blame them. Spam has become a plague spread by unscrupulous users.

Such a limit on emails generated by a surveillance controller is unacceptable. In case if some exceptions sensed at home, many nails may be generated and all are time critical.

...and many thanks for your code, it made thing much easier.

Do you know when the internet connections fails, or when the power goes down ?
For surveillance, you might need a GPSR shield and send a SMS and also have battery backup.

guy_c:
...and many thanks for your code, it made thing much easier.

No problem. Nice to know it helped you. :slight_smile:

If I could get a consensus on email services about authentication, I would add that to the email code on the playground. Some will take authentication without TLS or SSL, but many won't. And, of course, the Arduino ethernet library doesn't support either of those security protocols.

Yes, I am in the first phase, trying to figure out how email works. I guess that burgled will start by cutting the internet cable and perhaps the mains too. I should soon come back with a more robust solution I am working on with Jochen, an android developer

Heumm.. I might have been overoptimistic.
On Wed. 25th i sent 3 email, two to gmail and one to hotmail
the hotmail message has not been delivered (!)
I will remake more test next week and report here

Sorry for the mess: All messages where transmitted OK (I had a mistake in the destination)
The solution sketched above with smtp2go seems reliable.

I was wandering if someone experimented the use of an android email server to send emails via 3g/4g: The arduino would be connected to the home router's utp port and send requests to an android via wifi