---
title: "How to Send Emails With Attachments With Arduino, Esp32 and Esp8266"
url: "https://maker.wiznet.io/pranchal/projects/How-to-Send-Emails-With-Attachments-With-Arduino-Esp32-and-Esp8266/"
markdown_url: "https://maker.wiznet.io/pranchal/projects/How-to-Send-Emails-With-Attachments-With-Arduino-Esp32-and-Esp8266/md"
type: "UCC: User Created Content"
author: "pranchal"
author_url: "https://maker.wiznet.io/pranchal/"
original_author: "pranchal"
original_url: "https://www.instructables.com/How-to-Send-Emails-With-Attachments-With-Arduino-E/"
published: "2022-02-25"
language: "en"
hardware: ["Arduino Mega", "SD card", "WIZnet W5100"]
likes: 0
views: 354
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# How to Send Emails With Attachments With Arduino, Esp32 and Esp8266

> How to Send Emails With Attachments With Arduino, Esp32 and Esp8266

Original author: pranchal (source: https://www.instructables.com/How-to-Send-Emails-With-Attachments-With-Arduino-E/)

## Components

- **Arduino Mega** x 1
- **SD card** x 1
- **WIZnet W5100** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5100))

## Article

You can add attachments also, loaded from storage devices like SD or SPIFFS. Here is Arduino ethernet usage.

#### Supplies

- Arduino Mega

- enc28J60

- SD card

## Step 1: Select Correct Device ENC28J60 or W5100 Series

[![Select Correct Device ENC28J60 or W5100 Series](https://content.instructables.com/ORIG/FIZ/O3CX/KB6IDXDY/FIZO3CXKB6IDXDY.jpg?auto=webp&frame=1&fit=bounds&md=cd6e74ea202ab8ec4f21df15a5fa853a)](https://content.instructables.com/ORIG/FIZ/O3CX/KB6IDXDY/FIZO3CXKB6IDXDY.jpg?auto=webp&frame=1&fit=bounds&md=cd6e74ea202ab8ec4f21df15a5fa853a)

Arduino, normally, manage network with external device, the standard device like w5100 use Ethernet library the clones ENC28J60 have some libraries to select. To select your device you must go on EMailSenderKey.h library file and set the correct one

```
#define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO 	NETWORK_ENC28J60 // Default
```

The 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_W5100
```

This 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

[![Send Simple Email](https://content.instructables.com/ORIG/FLW/O3V6/KB6IDXE0/FLWO3V6KB6IDXE0.jpg?auto=webp&frame=1&width=875&fit=bounds&md=c498beba4db2ce75b6895754d247cbe9)](https://content.instructables.com/ORIG/FLW/O3V6/KB6IDXE0/FLWO3V6KB6IDXE0.jpg?auto=webp&frame=1&width=1024&fit=bounds&md=c498beba4db2ce75b6895754d247cbe9)

To send an email with Arduino you must find a provider that workwithout SSL or TLS, For my solution I use with the SendGrid provider. I think the usage is very very simple. So you must set the provider

```
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

[![Connect an SD Cart to Manage Attachments](https://content.instructables.com/ORIG/FT2/NS2Y/KB6IDXDZ/FT2NS2YKB6IDXDZ.jpg?auto=webp&frame=1&fit=bounds&md=500aa1d2c4f9f41ae6deb5a57517f29f)](https://content.instructables.com/ORIG/FT2/NS2Y/KB6IDXDZ/FT2NS2YKB6IDXDZ.jpg?auto=webp&frame=1&fit=bounds&md=500aa1d2c4f9f41ae6deb5a57517f29f)

Then to send attachments you must connect an SD card like in the schema.

## Step 4: Send Email With Attachment

To send an email with attachments you must find a provider that supports that functionality, my SendGrid provider does not support that and GMX the provider that I used for the test no more support. But if you find a new provider you can use this code to attach the files.

```
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);
```

## Step 5: The Result

[![The Result](https://content.instructables.com/ORIG/FXO/0CEC/KB6IDY25/FXO0CECKB6IDY25.jpg?auto=webp&frame=1&width=1024&fit=bounds&md=a8a1a076a1ea22bca4e7ef45eb85dc65)](https://content.instructables.com/ORIG/FXO/0CEC/KB6IDY25/FXO0CECKB6IDY25.jpg?auto=webp&frame=1&width=1024&fit=bounds&md=a8a1a076a1ea22bca4e7ef45eb85dc65)

Here is the email sent with an esp8266 and GMail provider (to use GMail you must enable an external program).

## Step 6: Library

You can find the library on GitHub?<https://github.com/xreef/EMailSender>

---

Source: https://maker.wiznet.io/pranchal/projects/How-to-Send-Emails-With-Attachments-With-Arduino-Esp32-and-Esp8266/
