Ethernet/Email/smtp_service.h
#ifndef __SMTP_SERVICE__H_
Line 1
#define __SMTP_SERVICE__H_
-
-
#include "email.h"
-
5
class SmtpService {
-
boolean _use_auth;
-
IPAddress _smtp_server;
-
unsigned int _port;
-
String _username;
10
String _password;
-
-
void read_response(EthernetClient& client) {
-
delay(4000);
-
while (client.available()) {
15
const char c = client.read();
-
Serial.print(c);
-
}
-
}
-
20
void send_line(EthernetClient& client, String line) {
-
const unsigned int MAX_LINE = 256;
-
char buffer[MAX_LINE];
-
line.toCharArray(buffer, MAX_LINE);
-
Serial.println(buffer);
25
client.println(buffer);
-
read_response(client);
-
}
-
-
public:
30
-
SmtpService(
-
const IPAddress& smtp_server,
-
const unsigned int port) : _use_auth(false),
-
_smtp_server(smtp_server),
35
_port(port) { }
-
-
SmtpService(
-
const IPAddress& smtp_server,
-
const unsigned int port,
40
const String& username,
-
const String& password) : _use_auth(true),
-
_smtp_server(smtp_server),
-
_port(port),
-
_username(username),
45
_password(password) { }
-
-
void send_email(const Email& email) {
-
EthernetClient client;
-
Chapter 11. Creating a Burglar Alarm with Email Notification • 190
report erratum • discuss
www.it-ebooks.info