How to Send Emails With Attachments With Arduino, Esp32 and Esp8266
How to Send Emails With Attachments With Arduino, Esp32 and Esp8266
0
Project description
Supplies
- Arduino Mega
- enc28J60
- SD card
Step 1: Select Correct Device ENC28J60 or W5100 Series
#define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_ENC28J60 // DefaultThe library loaded to manage this type of device is UIPEthernet, you can find the library on library manager of the Arduino IDE or you can change default network type
#define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_W5100This is the standard implementation and use Ethernet library. An important think to consider is that this Ethernet shield not support SSL or TLS, so you must find a provider SMTP that offer an SMTP connection without this type of encription. I create a topic on forum where you can add the provider you use, that you can find mine also.
Step 2: Send Simple Email
EMailSender emailSend("YOUR-SENDGRID-API-KEY", "YOUR-SENDGRID-PASSWD", "FROM-EMAIL", "smtp.sendgrid.net", 25);
Than you must create a message and send It
EMailSender::EMailMessage message;<br> message.subject = "Soggetto";
message.message = "Ciao come stai<br>io bene.<br>
EMailSender::Response resp = emailSend.send("email_to_receive@gmail.com", message);
Serial.println("Sending status: ");
Serial.println(resp.status);
Serial.println(resp.code);
Serial.println(resp.desc);
Step 3: Connect an SD Cart to Manage Attachments
Step 4: Send Email With Attachment
EMailSender::FileDescriptior fileDescriptor[1];<br> fileDescriptor[0].filename = F("test.txt");
fileDescriptor[0].url = F("/test.txt");
fileDescriptor[0].mime = MIME_TEXT_PLAIN;
fileDescriptor[0].encode64 = false;
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;
EMailSender::Attachments attachs = {1, fileDescriptor};
EMailSender::Response resp = emailSend.send("email_to_receive@gmail.com", message, attachs);




