EMailSender and SendGrid
To send an e-mail with EMAilSender, you can work with SendGrid. (https://sendgrid.com/en-us)
- create an account (free up to 100 mails per day).
install an application on the mobile phone for 2-level authentication
- create a SMTP Relay API key (full access)
copy the key and all your account information.
at the beginning of the code, don't forget to enter :
---------------------------------------------------
#include <Arduino.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EMailSender.h>
#define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_W5100 //If you're using a schield W5100.
byte mac[6] = { 0x** 0x**, 0x**, 0x**, 0x**, 0x** }; // Your Adress Mac
IPAddress ip(192, 168, *, ***); // Your Address IP
EMailSender emailSend(“apikey”, “your_password_apikey”, “your_mail”, “smtp.sendgrid.net”, 587 );
// apikey signals that we’re going to send a code related to an api module
// your_password_apikey is the password given by Sendgrid when requesting an SMTP Relay key.
// your_mail is the Sendgrid login address.
// You must use 587 as port
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
// while (!Serial) {}
delay(2000);
Serial.println("Port série ok");
// start the Ethernet connection:
pinMode(4, OUTPUT); // config for shield W5100 on MEGA2560
digitalWrite(4, HIGH); // config for shield W5100 on MEGA2560
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while(1);
}
Serial.print("Addresse IP ");
Serial.println(Ethernet.localIP());
EMailSender::EMailMessage message;
message.subject = "Test";
message.message = "This indicates a reboot of the arduino";
EMailSender::Response resp = emailSend.send("address@****.***", message);
Serial.print("Status: ");
Serial.println(resp.desc);
void loop()
{
if(Serial.read() == 'S') {
if(sendEmail_1()); // to send the mail
}
}
byte sendEmail_1() {
EMailSender::EMailMessage message;
message.subject = "Your mail title";
message.message = "Your information message";
EMailSender::Response resp = emailSend.send("address@****.***", message);
Serial.print("status: ");
Serial.println(resp.desc);
}
------------------------------------------------------------------
Just incorporate this sketch into your own and have fun!
I had to search a lot of forums to find a simple way to send email alerts from my Arduino system. (I have information coming from my heater, a pump, etc ...).
The EMailSender and SendGrid combination is the simplest.