user980: I want to make my Arduino connect via WiFi and then send an email. The idea is very simple, but the problem is that I've never worked with those protocols and other things before. I just wanted something that's already premade, so I would just change the information.
Is there a library or a function that sends the email?
If someone could help me to understand, so I can make it myself, that would be the best.

user4542: Sending gmail via SMTP from an Arduino is completely feasible. I am doing it from an Arduino MKR WIFI 1010 using the WIFINina library. I'm  pretty sure that my solution will work on any of the SAMD based Arduinos.
There is a bit o "setting up" to do, but it's not hard.
Check out my solution on my gitlab repo.
Be sure to do the config BEFORE trying to execute the code...
Good luck!
GF

user562: There may be a problem with sending Email from Arduino, but not where you are expecting it. SMTP protocol is super simple, even Arduino can handle it. But you will need SMTP server somewhere that will talk to your Arduino. SSL connections (as on Gmail) are out of consideration (code to handle the encryption would be too much for Arduino) so you'd have to find mail provider that provides plain SMTP - and there aren't many. If you will set up one yourself, say on your home PC with static IP address, it would be an invitation for spammers and a guaranteed way to get your IP blacklisted by Spamhaus. My advice would be to have Python, PHP or Perl script hosted somewhere that will handle HTTP POST requests from your Arduino and do Email sending. It is safer and simpler.

user666: You actually present 2 issues here, which can be handled separately:

You are concerned about having a WiFi, not an Ethernet shield. This doesnt affect at all for sending emails or any other network stuff. When you have internet connection, it is almost transparent from the programming side. So I recommend first to try your wifi shield connection and configuration as a separate problem, with a more simple task, as a simple HTTP_GET to a known web page. A function like this might help, assuming that you have an instance of WiFiClient (which is a Client), that has been connected (with connect) to the URL and port 80:
void http_get(Client& www, char website[], char webpage[], int timeout, Stream& stream) {
    if (www.connected()) {
        int n = www.print("GET ");
        www.print(webpage);
        www.print(" HTTP/1.1\r\n");
        www.print("Host: ");
        www.print(website);
        www.print("\r\n");
        www.print("\r\n");
    } else {
        stream.println(F("Connection failed get"));
        return;
    }

    /* Read data until either the connection is closed, or the idle timeout is reached. */
    unsigned long lastRead = millis();
    while (www.connected() && (millis() - lastRead < timeout)) {
        while (www.available()) {
            char c = www.read();
            stream.print(c);
            lastRead = millis();
        }
    }
}

The second problem is that you want to send an email. One you have a connection, it doesnt matter if it is wifi or wired. The above recommended libraries (SMTPClient, FullIP) will directly connect to your provider (e.g. gmail) and will request your gmail password, something that is not secure over non secure connections (and those libraries do not seem to provide secure layer), so personally I am not comfortable with that option. I have been using the temboo service, that allows to send emails, and I have found it to be quite convenient and simple. Furthermore, they also have many other services. The service stores your gmail or whatever provider credentials, and you access the service via a Secret Key and App Password they provide. While this keys might not be fully secure to be sent via non secure layers, at least it only compromises your app in the cloud application, which you might simply manage, and not your full email account. (Disclaimer: I have no relation with temboo, and there might be other similar services for this task, e.g. Carriots, I simply say that I have used them with success for this task and feel it is relatively simple). Your code using temboo, could be something like:
TembooChoreo choreo(client); // your WiFiClient object

// Set Temboo account credentials
choreo.setAccountName(temboo_account);
choreo.setAppKeyName(temboo_app);
choreo.setAppKey(temboo_app_key);

// credential is the name of your gmail profile in temboo
choreo.setCredential(credential);
choreo.addInput("MessageBody", body);
choreo.addInput("Subject", subject);
choreo.addInput("ToAddress", address);

//Identify the Choreo to run
choreo.setChoreo("/Library/Google/Gmail/SendEmail");

choreo.run();
choreo.close();



user368: What you're looking for is a SMTP (Simple Mail Transport Protocol) library. A Google search finds 2 for the Arduino:

SMTPClient
This seems to be a minimal-capability SMTP-only library that piggybacks on top of a connection library.

FullIP
This seems to be a full IP package for the Arduino that works with select network devices which includes SMTP capability.



980: <p>I want to make my Arduino connect via WiFi and then send an email. The idea is very simple, but the problem is that I've never worked with those protocols and other things before. I just wanted something that's already premade, so I would just change the information.</p>

<p>Is there a library or a function that sends the email?</p>

<p>If someone could help me to understand, so I can make it myself, that would be the best.</p>
 4542: <p>Sending gmail via SMTP from an Arduino is completely feasible. I am doing it from an Arduino MKR WIFI 1010 using the WIFINina library. I'm  pretty sure that my solution will work on any of the SAMD based Arduinos.</p>
<p>There is a bit o &quot;setting up&quot; to do, but it's not hard.</p>
<p>Check out my solution on my <a href="https://gitlab.com/gratefulfrog/arduino-wifinina-gmail-smtp" rel="nofollow noreferrer">gitlab repo</a>.</p>
<p>Be sure to do the config BEFORE trying to execute the code...
Good luck!
GF</p>
 562: <p>There may be a problem with sending Email from Arduino, but not where you are expecting it. SMTP protocol is super simple, even Arduino can handle it. But you will need SMTP server somewhere that will talk to your Arduino. SSL connections (as on Gmail) are out of consideration (code to handle the encryption would be too much for Arduino) so you'd have to find mail provider that provides plain SMTP - and there aren't many. If you will set up one yourself, say on your home PC with static IP address, it would be an invitation for spammers and a guaranteed way to get your IP blacklisted by Spamhaus. My advice would be to have Python, PHP or Perl script hosted somewhere that will handle HTTP POST requests from your Arduino and do Email sending. It is safer and simpler.</p>
 666: <p>You actually present 2 issues here, which can be handled separately:</p>

<ul>
<li><p>You are concerned about having a WiFi, not an Ethernet shield. This doesnt affect at all for sending emails or any other network stuff. When you have internet connection, it is almost transparent from the programming side. So I recommend first to try your wifi shield connection and configuration as a separate problem, with a more simple task, as a simple HTTP_GET to a known web page. A function like this might help, assuming that you have an instance of WiFiClient (which is a Client), that has been connected (with connect) to the URL and port 80:</p>

<pre><code>void http_get(Client&amp; www, char website[], char webpage[], int timeout, Stream&amp; stream) {
    if (www.connected()) {
        int n = www.print("GET ");
        www.print(webpage);
        www.print(" HTTP/1.1\r\n");
        www.print("Host: ");
        www.print(website);
        www.print("\r\n");
        www.print("\r\n");
    } else {
        stream.println(F("Connection failed get"));
        return;
    }

    /* Read data until either the connection is closed, or the idle timeout is reached. */
    unsigned long lastRead = millis();
    while (www.connected() &amp;&amp; (millis() - lastRead &lt; timeout)) {
        while (www.available()) {
            char c = www.read();
            stream.print(c);
            lastRead = millis();
        }
    }
}
</code></pre></li>
<li><p>The second problem is that you want to send an email. One you have a connection, it doesnt matter if it is wifi or wired. The above recommended libraries (SMTPClient, FullIP) will directly connect to your provider (e.g. gmail) and will request your gmail password, something that is not secure over non secure connections (and those libraries do not seem to provide secure layer), so personally I am not comfortable with that option. I have been using the <a href="http://www.temboo.com" rel="nofollow">temboo</a> service, that allows to send emails, and I have found it to be quite convenient and simple. Furthermore, they also have many other services. The service stores your gmail or whatever provider credentials, and you access the service via a Secret Key and App Password they provide. While this keys might not be fully secure to be sent via non secure layers, at least it only compromises your app in the cloud application, which you might simply manage, and not your full email account. (Disclaimer: I have no relation with temboo, and there might be other similar services for this task, e.g. <a href="https://www.carriots.com/documentation/arduino" rel="nofollow">Carriots</a>, I simply say that I have used them with success for this task and feel it is relatively simple). Your code using temboo, could be something like:</p>

<pre><code>TembooChoreo choreo(client); // your WiFiClient object

// Set Temboo account credentials
choreo.setAccountName(temboo_account);
choreo.setAppKeyName(temboo_app);
choreo.setAppKey(temboo_app_key);

// credential is the name of your gmail profile in temboo
choreo.setCredential(credential);
choreo.addInput("MessageBody", body);
choreo.addInput("Subject", subject);
choreo.addInput("ToAddress", address);

//Identify the Choreo to run
choreo.setChoreo("/Library/Google/Gmail/SendEmail");

choreo.run();
choreo.close();
</code></pre></li>
</ul>
 368: <p>What you're looking for is a <strong>SMTP (Simple Mail Transport Protocol) library</strong>. A Google search finds 2 for the Arduino:</p>
<ul>
<li><p><a href="https://github.com/gregington/SMTPClient" rel="noreferrer">SMTPClient</a></p>
<p>This seems to be a minimal-capability SMTP-only library that piggybacks on top of a connection library.</p>
</li>
<li><p><a href="https://github.com/bibi21000/arduino-fullip" rel="noreferrer">FullIP</a></p>
<p>This seems to be a full IP package for the Arduino that works with select network devices which includes SMTP capability.</p>
</li>
</ul>
