four seconds (SMTP servers usually are very busy, because they have to send
a lot of spam), and then it reads all the data sent back by the server and
outputs it to the serial port for debugging purposes.
Before we can process responses, we have to send requests.
in line 21, sends a single command to an SMTP server. You have to pass the
connection to the server as an
to send has to be a
To send the data stored in a
it refers to. We can use
two methods do not return a pointer to the string s internal buffer. Instead,
they expect you to provide a sufficiently large
why we copy
line
s content to
ports. After we ve sent the data, we read the server s response and print it to
the serial port.
There aren t any surprised in the public interface. There are two constructors.
The first, on line 32, expects the SMTP server s IP address and its port. If you
use it, the
SmtpService
To authenticate against the SMTP service using a username and a password,
you have to use the second constructor, starting in line 38. In addition to the
SMTP server s IP address and port, it expects the username and password
encoded in Base64.
The
send_email
method is the largest piece of code in our class, but it s also one
of the simplest. It mimics exactly our
mentioning is line 57. Here we check whether authentication information has
been provided in the constructor. If not, we send the
authentication information has been provided, we send the
and the corresponding authentication information.
Let s use our classes now to actually send an email:
Ethernet/Email/Email.ino
#include <SPI.h>
Line 1
#include <Ethernet.h>
-
#include "smtp_service.h"
-
-
const unsigned int
5
const unsigned int
-
const
String
-
const
String
-
-
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
10
IPAddress my_ip(192, 168, 2, 120);
-
Chapter 11. Creating a Burglar Alarm with Email Notification
EthernetClient
String
object.
String
object, we need to access the character data
toCharArray
or
getBytes
buffer
before we output it to the serial and Ethernet
class assumes you re not using authentication.
telnet
SMTP_PORT = 2525;
BAUD_RATE = 9600;
USERNAME
= "bm90bXl1c2VybmFtZQ==";
PASSWORD
= "bm90bXlwYXNzd29yZA==";
www.it-ebooks.info
send_line
instance, and the line you d like
to retrieve this information. These
char
array and its size. That s
session. The only thing worth
HELO
command. If
EHLO
// Encoded in Base64.
// Encoded in Base64.
192
, beginning
command
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?