I got error 530 5.7.0 from gmail server when trying to send an email from Arduino and Ethernet screen.
I want to send an email from my arduino uno forum. I bought an Ethernet screen for it. I found the code to send email using the Ethernet screen below, but I failed. The Gmail server said the “530 5.7.0” error code, but I don’t know what that means. What did I misunderstand?
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };
IPAddress ip( 10, 6, 0, 248 );
IPAddress gateway( 10, 6, 0, 1 );
IPAddress subnet( 255, 255, 255, 0 );
char server[] = "smtp.gmail.com";
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,25) == 1) {
Serial.println(F("connected"));
} else {
Serial.println(F("connection failed"));
return 0;
}
if(!eRcv()) return 0;
Serial.println(F("Sending helo"));
client.println(F("helo 1.2.3.4"));
if(!eRcv()) return 0;
Serial.println(F("Sending From"));
client.println(F("MAIL From: <me@mydomain.com>"));
if(!eRcv()) return 0;
Serial.println(F("Sending To"));
client.println(F("RCPT To: <receiver@gmail.com>"));
if(!eRcv()) return 0;
Serial.println(F("Sending DATA"));
client.println(F("DATA"));
if(!eRcv()) return 0;
Serial.println(F("Sending email"));
client.println(F("To: You <receiver@gmail.com>"));
client.println(F("From: Me <me@mydomain.com>"));
client.println(F("Subject: Arduino email test\r\n"));
client.println(F("This is from my Arduino!"));
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(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(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"));
}
source
share