Sending Emails Using the Arduino Uno Wifi Rev2 Board and the EmailSender library

Hello, I'm currently working on a project where I'm using an Arduino Uno Wifi Rev 2 to send an email, but every time I test it out it returns "Could not connect to mail server." Using some other test code, I know that the board works with connecting to wifi and to the website smtp.gmail.com, but it isn't working. I've also tried uploading the google.com443 certificate onto it and have the sender email set to allow less security.

Does anyone know why it isn't working? Any help would be appreciated!

#include "Arduino.h"
#include <EMailSender.h>
#include <WiFiNINA.h>

uint8_t connection_state = 0;
uint16_t reconnect_interval = 10000;

const char* ssid = "WiFi SSID";
const char* password = "WiFi Password";

EMailSender emailSend("Sender email (That has less security settings on)", "Sender email password");

uint8_t WiFiConnect(const char* nSSID = nullptr, const char* nPassword = nullptr)
{
    static uint16_t attempt = 0;
    Serial.print("Connecting to ");
    if(nSSID) {
        WiFi.begin(nSSID, nPassword);
        Serial.println(nSSID);
    }

    uint8_t i = 0;
    while(WiFi.status()!= WL_CONNECTED && i++ < 50)
    {
        delay(200);
        Serial.print(".");
    }
    ++attempt;
    Serial.println("");
    if(i == 51) {
        Serial.print("Connection: TIMEOUT on attempt: ");
        Serial.println(attempt);
        if(attempt % 2 == 0)
            Serial.println("Check if access point available or SSID and Password\r\n");
        return false;
    }
    Serial.println("Connection: ESTABLISHED");
    Serial.print("Got IP address: ");
    Serial.println(WiFi.localIP());
    return true;
}

void Awaits()
{
    uint32_t ts = millis();
    while(!connection_state)
    {
        delay(50);
        if(millis() > (ts + reconnect_interval) && !connection_state){
            connection_state = WiFiConnect();
            ts = millis();
        }
    }
}

void setup()
{
    Serial.begin(115200);

    connection_state = WiFiConnect(ssid, password);
    if(!connection_state)  // if not connected to WIFI
        Awaits();          // constantly trying to connect

    EMailSender::EMailMessage message;
    message.subject = "Email";
    message.message = "Email Sent!";


    EMailSender::Response resp = emailSend.send("Recipient email account", message);

    Serial.println("Sending status: ");

    Serial.println(resp.status);
    Serial.println(resp.code);
    Serial.println(resp.desc);
    delay(1000);
  

}

void loop()
{

}

@r0vert, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

Thank you! I fixed up the post

Hi, did you ever get a resolution on this - I am stuck with the exact same issue!

I'm also stuck on this. Did you come right and possibly share the outcome?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.