Trying to send email by using Arduino ethernetshield

Hi :slight_smile:
I want to send an email by using arduino ethernet shield.
So far I have tried to use google smtp server (smtp-relay.gmail.com, port 587)
As you can probably tell I'm a beginner at this.
I really hope someone can help me :slight_smile:

This is the setup part of the code:

#include <Ethernet.h>
#include <SPI.h>
byte mac[]= { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,103);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
char server[]="smtp-relay.gmail.com";
int port=587;
EthernetClient client;

void setup()
{
Serial.begin(115200);
Ethernet.begin(mac,ip,gateway,gateway,subnet);
delay(2000);

}

And this is the sending email part of the code:

Serial.println("Connecting...");
if(client.connect(server, port))
Serial.println("Connected");
client.println("EHLO ");

This EHLO part I'm really unsure about :frowning:

client.println("AUTH LOGIN");
client.println("Mail in base 64 code");
client.println("Password in base 64 code");
client.print("MAIL FROM:");
client.println("fromMail@gmail.com");
client.print("RCPT TO:");
client.println("toMail@gmail.com");
client.println("DATA");
client.print("from");
client.println("fromMail@gmail.com");
client.print("to:");
client.println("toMail@gmail.com");
client.println("SUBJECT: Something");
client.println();
client.println("This is the body.");
client.println(".");
client.println("QUIT");
client.stop();
Serial.println("Sent");

The Arduino seems to run trough the whole code. In the serial monitor it prints "Connecting..", "Connected" and "Sent" but no email so far :confused:

Anyone have any ideas as to how I can fix it?

Anyone have any ideas as to how I can fix it?

Certainly. Get the process working on the PC first, where you have a lot more debugging tools. Only when you KNOW that you can send e-mail from a PC application, using TCP-IP, should you attempt to do it on the Arduino.

You will need a mail service that will let you connect to their SMTP (Simple Mail Transfer Protocol) server without using TLS (Transport Layer Security, the replacement for SSL: Secure Sockets Layer). The SMTP protocol is easy to use. See: Arduino Playground - Email

Because spammers will take advantage of any unsecured SMPT server you will almost certainly be required to authenticate yourself with a username and password. More on authenticating using the PLAIN, LOGIN, and CRAM-MD5 protocols:

It is entirely possible that the server is protecting you from making your username and password public by not allowing PLAIN or LOGIN authentication. The base64 versions are trivial to convert back into plaintext.

You should probably look at the messages being sent by the server. They will likely give you a clue as to what you are doing wrong.