Go Down

Topic: How to access smtp.gmail.com or other to send email (Read 43780 times) previous topic - next topic

katonafull

I found another sketch.
http://www.jucetechnology.com/wordpress/simple-burglar-ethernet-shield-connection/ Why don't have to use it IPAddress, IPAddress gateway, and IPAddress subnet ? And what is the deficiency of this example? Why is it much easier than your example? Ex cuse me for my questions! I would like to understand the differences.

appliedpr

katonafull,

I have been following your dialog for some time, now.  The reason being that I have exactly your same problem.  Today, I was able for the first time to communicate and send my first email using the simple burglar alarm sketch that you mention. I just wanted to thank you, because I was not successful with your referenced topic either.

The only changes that have to be made to the burglar alarm sketch is to limit to one or two emails per event because as is, it sends a train of emails without holding to comply with the SMTP2GO server limits.

Thank you again.

SurferTim

#17
Dec 20, 2016, 01:58 pm Last Edit: Dec 20, 2016, 03:46 pm by SurferTim
The "simple" burglar alarm sketch does no error checking. It retrieves the response but doesn't display it. If something goes wrong, it is almost impossible to determine where the problem is.

edit: It simple sketch will also return success even if the send failed for any reason, like user/password incorrect, TO or FROM address errors, etc.

sandyproject21

I compile the codes and there is no error.
I run the serial monitor. Connection OK but email failed.

What can I do to test email send from arduino? I am using the ethernet shield W5100.

SurferTim

If your email client sketch had error checking, you would know why it failed. This example in the playground has error checking.
http://playground.arduino.cc/Code/Email

hanluu

Hi surfertim

the smtp2go user is the gmail( hanluu@gmail.com) address or just user name, because i saw my smtp2go account show the user name (hanluu).thanks

SurferTim

I use the email address I registered with, but it must be base64 encoded.
https://www.base64encode.org/
Same with the password. Base64 encoded.

hanluu

email sent.
 thank you very much
i just change my user name ''hanluu'' into email address then BOOM. I GOT MAIL. THANKS AGAIN.

hanluu

can you show me how to add a float switch to trigger the email? thank you.

SurferTim

I suppose you got the code here.
http://playground.arduino.cc/Code/Email


If so, in the second example at line 37
Code: [Select]
// replace this
  if(inChar == 'e')

// with something like this
  if(triggerPin == HIGH)

hanluu

Hi.

Can you fix this code to send only 1 email when it trigger the sensor,right now when sensor trigger it send alot of mail. thank you.


Code: [Select]

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
int LED = 13;                // choose the pin for the LED
int SENSOR = 2;               // choose the input pin (for SENSOR sensor)
int VAL =digitalRead(SENSOR);                    // variable for reading the pin status
int SENSORS = LOW;           

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

char server[] = "mail.smtp2go.com";
int port = 2525; // You can also try using Port Number 25, 8025 or 587.

File myFile;

EthernetClient client;

void setup()
{

  Serial.begin(9600);
  pinMode(LED, OUTPUT);      // declare LED as output
  pinMode(SENSOR, INPUT);     // declare sensor as input
  digitalWrite(LED, LOW);
 
Ethernet.begin(mac);
delay(2000);
Serial.println(Ethernet.localIP());
Serial.println(F("Ready. Press 'e' to send."));

}


void loop(){

 if (digitalRead(SENSOR) == HIGH) {           
    digitalWrite(LED, HIGH);  // turn LED ON
  ////delay (300);
   
    if (SENSORS == LOW) {
      Serial.println("Motion detected!");
    SENSORS = HIGH;
    }
  }
  else {
      digitalWrite(LED, LOW); // turn LED OFF
 
      if (SENSORS == HIGH){
      Serial.println("Motion ended!");
      SENSORS = LOW;
    }
  }
 
byte inChar;

inChar =  digitalRead(SENSOR);               /// Serial.read(); 

if(inChar == HIGH  )
{
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 hello"));
// replace 1.2.3.4 with your Arduino's ip
client.println("EHLO 192.168.0.31 ");
if(!eRcv()) return 0;

Serial.println(F("Sending auth login"));
client.println("auth login");
if(!eRcv()) return 0;

Serial.println(F("Sending User"));
// Change to your base64 encoded user
client.println(F("yyyyyyyyyyyyyyyyy"));


if(!eRcv()) return 0;

Serial.println(F("Sending Password"));
// change to your base64 encoded password
client.println(F("xxxxxxxxxxx"));


if(!eRcv()) return 0;

// change to your email address (sender)
Serial.println(F("Sending From"));
client.println("MAIL From: <hanluu@hotmail.com>");
if(!eRcv()) return 0;

// change to recipient address
Serial.println(F("Sending To"));
client.println("RCPT To: <hanluu@gmail.com>");
if(!eRcv()) return 0;

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

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

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

// change to your address
client.println("From: <hanluu@hotmail.com>");

client.println("Subject: Your Subject");

client.println("Hi! Simple test message");

client.println(".");

if(!eRcv()) return 0;

Serial.println(F("Sending QUIT"));
client.println("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"));
}




SurferTim

Take a look at the "BlinkWithoutDelay" example included with the IDE. That should give you a way to prevent multiple sends.

yash023

Hello,

Anyone can help me how to data sent to our Gmail account using Arduino and ESP8266(temperature and humidity) could u please send an anyone a sample code.

TimG123

This is a very useful thread, thanks to all.  I got stuck with an error message saying that I wasn't allowed to send messages to SMTP2GO as I didn't have a senders domain.  This is apparently a new security feature of SMTP2GO.  Here's the steps to take to get it working:

1. Create account at https://www.smtp2go.com/
2. Add your email address as a user. Note that each user has their own passwords (separate to the admin account created above).
3. To get around the recent issue of needing to have your own sender domain, which is a problem if you want to use say a gmail or ISP issued email address: Make contact with SMTP2GO Support and explain your use case, and they will adjust your account appropriately. This way you can keep Sender Domains blank. If you try and enter a sender domain that you don't own, you'll receive the error message "The domain you have entered is not allowed. Please note that you must have control of the DNS of any domain that you add." (To check if this issue is occurring, open the serial monitor before code execution, and after "235 Authentication Succeeded" you will see an error "That user is not allowed to send").
4. Restrict senders to your chosen email addresses - this provides some level of security against spammers.
5. Incorporate the code at https://www.smtp2go.com/setupguide/arduino/  into your Arduino sketch.
6. The username and password must be sent using base64 encoding by the Arduino to SMTP2GO. You can use https://www.base64encode.org/ (amongst other sites) to do the encodes. (To check if you got the password right, open the serial monitor before code execution and look for "Sending Password".  The next line should say "235 Authentication succeeded".  Otherwise, check you've got the right password and done the base64 encoding correctly).

samsingania44

Gmail Customer Service Number+1833-222-2937

Is an especially open and shrewd stage. Regardless, it without question can have numerous segments that can be really perplexing for the customers. Make an effort not to stress, at Gmail Customer Service number, we outfit you with a 24×7 help concerning finding answers for a wide scope of your Gmail disorders. gmail phone number, We offer 'Constant" advantage with our specific push utilities to our customers for their straightforwardness and solace. gmail customer care number +1833-222-2937

Go Up