SMPT2GO

I am using MKR1010 to send an Gmail via SMPT2GO - an SMPT server.. I am sure my code works perfectly fine, but I have an error when executing the code. It said “550 that smtp username’s account is not allowed to send ”. I looked up online and found that many comments under tutorials about SMPT2GO said the same problem. Can anyone explain why, please? Here are the sources and picture of the code.

Found some similar comment around year 2018:

Official guide from the SMPT2GO:

https://www.smtp2go.com/setupguide/arduino/

My own version to make it work with MKR1010

/*

This example connects to an unencrypted Wifi network.
Then it prints the MAC address of the board,
the IP address obtained, and other network details.

created 13 July 2010
by dlf (Metodo2 srl)
modified 31 May 2012
by Tom Igoe
*/
#include <SPI.h>
#include <WiFiNINA.h>

#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char server[] = "mail.smtp2go.com"; 
int port = 25; // You can also try using Port Number 25, 8025 or 587.

WiFiClient client;


////////////////////////////  VOID SETUP ////////////////////////////




void setup() {
 //Initialize serial and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }
 // check for the WiFi module:
 if (WiFi.status() == WL_NO_MODULE) {
   Serial.println("Communication with WiFi module failed!");
   // don't continue
   while (true);
 }

 String fv = WiFi.firmwareVersion();
 if (fv < "1.0.0") {
   Serial.println("Please upgrade the firmware");
 }

 // attempt to connect to Wifi network:
 while (status != WL_CONNECTED) {
   Serial.print("Attempting to connect to open SSID: ");
   Serial.println(ssid);
   status = WiFi.begin(ssid);

   // wait 10 seconds for connection:
   delay(10000);

 }

 // you're connected now, so print out the data:
 Serial.print("You're connected to the network");
 printCurrentNet();
 printWifiData();

 delay(3000);
 Serial.println(F("Ready. Press 'e' to send."));



 





}






////////////////////  VOID LOOP /////////////////////////








void loop() {
 byte inChar;

 inChar = Serial.read();

 if(inChar == 'e')  {
   if(sendEmail()) Serial.println(F("Email sent"));
   else Serial.println(F("Email failed"));
}




 
}











////////////////////////// SUB FUNCTION ////////////////////////




void printWifiData() {
 // print your board's IP address:
 IPAddress ip = WiFi.localIP();
 Serial.print("IP Address: ");
 Serial.println(ip);
 Serial.println(ip);

 // print your MAC address:
 byte mac[6];
 WiFi.macAddress(mac);
 Serial.print("MAC address: ");
 printMacAddress(mac);

 // print your subnet mask:
 IPAddress subnet = WiFi.subnetMask();
 Serial.print("NetMask: ");
 Serial.println(subnet);

 // print your gateway address:
 IPAddress gateway = WiFi.gatewayIP();
 Serial.print("Gateway: ");
 Serial.println(gateway);
}

void printCurrentNet() {
 // print the SSID of the network you're attached to:
 Serial.print("SSID: ");
 Serial.println(WiFi.SSID());

 // print the MAC address of the router you're attached to:
 byte bssid[6];
 WiFi.BSSID(bssid);
 Serial.print("BSSID: ");
 printMacAddress(bssid);

 // print the received signal strength:
 long rssi = WiFi.RSSI();
 Serial.print("signal strength (RSSI):");
 Serial.println(rssi);

 // print the encryption type:
 byte encryption = WiFi.encryptionType();
 Serial.print("Encryption Type:");
 Serial.println(encryption, HEX);
}

void printMacAddress(byte mac[]) {
 for (int i = 5; i >= 0; i--) {
   if (mac[i] < 16) {
     Serial.print("0");
   }
   Serial.print(mac[i], HEX);
   if (i > 0) {
     Serial.print(":");
   }
 }
 Serial.println();
}







///////// EMAIL SUB FUNCTION //////////////////





byte sendEmail()
{
byte thisByte = 0;
byte respCode;

if(client.connect(server,port) == 1) {
Serial.println(F("connected"));
} else {
Serial.println(F("connection failed"));
return 0;
}

if(!eRcv()) return 0;

Serial.println(F("Sending hello"));
// replace 1.2.3.4 with your Arduino's ip
client.println("EHLO 192.168.333.123");
if(!eRcv()) return 0;

Serial.println(F("Sending auth login"));
client.println("auth login");
if(!eRcv()) return 0;

Serial.println(F("Sending User"));
// Change to your base64 encoded user
client.println(F("anNqc3NqMjAbC5jb20=")); 


if(!eRcv()) return 0;

Serial.println(F("Sending Password"));
// change to your base64 encoded password
client.println(F("VGllbm5anM=")); 


if(!eRcv()) return 0;

// change to your email address (sender)
Serial.println(F("Sending From"));
client.println("MAIL From: <a@gmail.com>");
if(!eRcv()) return 0;

// change to recipient address
Serial.println(F("Sending To"));
client.println("RCPT To: <b@gmail.com>");
if(!eRcv()) return 0;

Serial.println(F("Sending DATA"));
client.println("DATA");
if(!eRcv()) return 0;

Serial.println(F("Sending email"));

// change to recipient address
client.println("To: Rachel <b@gmail.com>");

// change to your address
client.println("From: Susan <a@gmail.com>");

client.println("Subject: Your Subject"); 

client.println("Hi! Simple test message");

client.println(".");

if(!eRcv()) return 0;

Serial.println(F("Sending QUIT"));
client.println("QUIT");
if(!eRcv()) return 0;

client.stop();

Serial.println(F("disconnected"));

return 1;
}

byte eRcv()
{
byte respCode;
byte thisByte;
int loopCount = 0;

while(!client.available()) {
delay(1);
loopCount++;

// if nothing received for 10 seconds, timeout
if(loopCount > 10000) {
client.stop();
Serial.println(F("\r\nTimeout"));
return 0;
}
}

respCode = client.peek();

while(client.available())
{ 
thisByte = client.read(); 
Serial.write(thisByte);
}

if(respCode >= '4')
{
efail();
return 0; 
}

return 1;
}


void efail()
{
byte thisByte = 0;
int loopCount = 0;

client.print(F("QUIT"));

while(!client.available()) {
delay(1);
loopCount++;

// if nothing received for 10 seconds, timeout
if(loopCount > 10000) {
client.stop();
Serial.println(F("\r\nTimeout"));
return;
}
}

while(client.available())
{ 
thisByte = client.read(); 
Serial.write(thisByte);
}

client.stop();

Serial.println(F("disconnected"));
}

For anyone who is interested, this code require a second tab in the IDE that must name arduino_secrets.h and put one line:

#define SECRET_SSID "yourssid"

Could you please use CODE TAGS ( </> ) in future as the forum has been know to change characters when a sketch is not formatted properly.
It also make it much easier to read.

Sorry this is my first time posting codes and questions in a forum. I have fixed it. Thanks!

Hi,

I have found the article that related to the problem. At the beginning, I have suspected that Gmail has some changes in their policies, and here it is:

This article talks about how you are NOT GOING TO BE ABLE TO USE GMAIL TO SEND EMAIL. Thank you,