
details
Link
Feature
Connect DHCP and Send email.
The most important things to keep in mind are:
- ethernet shield ip settings
- ethernet shield mac address
- SMTP settings to send email
My router is in DHCP so it dynamically set the IP address.
No problems for the MAC address: it can be set as you need.
There are two ways to send an email with Ethernet Shield:
- Temboo service has a library to send an email with Gmail account (instruction here )
- SMTP2GO service to send up to 10 emails with its SMTP free service (here you can register )
I choose SMTP2GO cause I discovered Temboo too late when I finished deploying with SMTP2GO.
If someone uses Temboo let me know your opinion.
I used Nicolaj Joergensen code, it’s very clear and well explained.
Code
#include <SPI.h>;
#include <Ethernet.h>;
// Arduino network information
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
EthernetClient client;
char smtpServer[] = "smtpcorp.com";
void setup()
{
Serial.begin(9600); // for debug mode
setupComm();
}
void loop()
{
email("hallo");
delay(1000);
}
// ethernet shield connection init
void setupComm()
{
Serial.println("Trying to connect");
if (!Ethernet.begin(mac)){
Serial.println("Failed to DHCP");
// verifyng connection
while(true);
}
delay(10000);
// IP address is:
Serial.print("IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
// now I send email
bool email(char* text)
{
bool success = false;
Serial.println("Sending email...");
if (client.connect(smtpServer, 2525)){ //2525 is SMTP Server port
Serial.println("connected");
delay(100);
client.println("EHLO arduino");
for(int i=0; i<999; ++i){
if(client.read() > 0)
break;
}
Serial.println("responded");
client.println("AUTH LOGIN"); //see "http://base64-encoder-online.waraxe.us/"
client.println("xxxxxxxxxx"); //Type your username and encode it
client.println("yyyyyyyyyy"); //Type your password and encode it</p>
// Put your "from" email address here
client.println("MAIL FROM:<dumm@gmail.com>"); //Seems you can write what you want here...
for(int i=0; i<999; ++i){
if(client.read() > 0)
break;
}
client.println("RCPT TO:<mail@mail.com>");
for(int i=0; i<999; ++i){
if(client.read() > 0)
break;
}
client.println("DATA");
for(int i=0; i<999; ++i){
if(client.read() > 0)
break;
}
//Sender
client.println("from: mail@mail.com"); //Sender address
client.println("to: mail@mail.com"); //Receiver address
client.println("SUBJECT: From your arduino");
client.println("");
client.println(text);
client.println(".");
client.println("QUIT");
for (int i = 0; i<999; ++i){
if(i > 998){
Serial.println("error: No response");
}
if(client.read() > 0)
break;
}
success = true;
client.println();
Serial.println("end");
}
else {
Serial.println("Failed");
client.println("QUIT"); //Disconnection
}
client.stop();
return success;
}банки онлайн заявка на кредит наличными
COMMENTS