Skip to content

wificlientsecure fails to connect with smtp2go, but works with gmail #3932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kapyaar opened this issue Dec 7, 2017 · 7 comments · Fixed by #4033
Closed

wificlientsecure fails to connect with smtp2go, but works with gmail #3932

kapyaar opened this issue Dec 7, 2017 · 7 comments · Fixed by #4033
Assignees
Milestone

Comments

@kapyaar
Copy link

kapyaar commented Dec 7, 2017

Please fill the info fields, it helps to get you faster support ;)

if you have a stack dump decode it:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/stack_dump.rst

for better debug messages:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst

----------------------------- Remove above -----------------------------

Basic Infos

Hardware

Hardware: ESP-12
Core Version: 2.4.0-rc2

Description

I am working on the ESP8266 gmail sender (http://www.instructables.com/id/ESP8266-GMail-Sender/) to send email using WiFiClientSecure. I can get it to work with gmail, but fail to get even connect to the server with mail.smtp2go.com.

Settings in IDE

Module: ?nodeMCU 0.9?
Flash Size: ?4MB/1MB?
CPU Frequency: ?80Mhz?
Flash Mode: ?DOUT?
Flash Frequency: ?40Mhz?
Upload Using: ?SERIAL?
Reset Method: ?ck / nodemcu?

Sketch

#include <Gsender.h>
#include "ESP8266WiFi.h"


#pragma region Globals
const char* ssid = "MyWiFi"; // WIFI network name
const char* password = "Password"; // WIFI network password
uint8_t connection_state = 0; // Connected to WIFI or not
uint16_t reconnect_interval = 10000; // If not connected wait time to try again
#pragma endregion Globals

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);
  } else {
    WiFi.begin(ssid, password);
    Serial.println(ssid);
  }

  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();
  if (!connection_state) // if not connected to WIFI
    Awaits(); // constantly trying to connect

  Gsender *gsender = Gsender::Instance(); // Getting pointer to class instance
  const char* EMAILBASE64_LOGIN = "base64_encoded_loginemail";
  const char* EMAILBASE64_PASSWORD = "base64_encoded_password";


  const char* FROM = "[email protected]";

  String subject = "Subject is optional";
  if (gsender->Subject(subject)->Send("[email protected]", "Alerts are working now")) {


    Serial.println("Message send.");
  } else {
    Serial.print("Error sending message: ");
    Serial.println(gsender->getError());
  }
}

void loop() {}

Debug Messages

With gmail I get the following:

Connecting to :smtp.gmail.com:465
please start sntp first !
220 smtp.gmail.com ESMTP n3sm3479813qte.14 - gsmtp

HELO localhost:
250 smtp.gmail.com at your service

AUTH LOGIN:
334 VXNlcm5hbWU6

EMAILBASE64_LOGIN: d*********************************9t
334 UGFzc3dvcmQ6

EMAILBASE64_PASSWORD:b************E=
235 2.7.0 Accepted

MAIL FROM: <w**********[email protected]>
250 2.1.0 OK n3sm3479813qte.14 - gsmtp

RCPT TO: <a*******[email protected]>
250 2.1.5 OK n3sm3479813qte.14 - gsmtp
DATA:
354  Go ahead n3sm3479813qte.14 - gsmtp
250 2.0.0 OK 1512667183 n3sm3479813qte.14 - gsmtp
221 2.0.0 closing connection n3sm3479813qte.14 - gsmtp
============================================

with mail.smtp2go.com, I tried different port numbers and get teh following.
Connecting to :mail.smtp2go.com:2525
please start sntp first !
ssl->need_bytes=8301 > 6859

Connecting to :mail.smtp2go.com:465
please start sntp first !
Error: connection lost

Connecting to :mail.smtp2go.com:25
please start sntp first !
ssl->need_bytes=8301 > 6859
@5chufti
Copy link
Contributor

5chufti commented Dec 8, 2017

here is an example that says to work with smtp2go
https://playground.arduino.cc/Code/Email
I didn't look for differences, maybe you find some hint ...

@kapyaar
Copy link
Author

kapyaar commented Dec 8, 2017

@5chufti Oh, I can get to work on smtp2go with non secure client. It is just the secure client part that is not working.

@igrr
Copy link
Member

igrr commented Dec 26, 2017

Thanks for reporting this @kapyaar, looks like our implementation of max_fragment_length extension may have a bug. Working on a fix for this...

@igrr igrr self-assigned this Dec 26, 2017
@igrr igrr added this to the 2.5.0 milestone Dec 26, 2017
igrr added a commit that referenced this issue Dec 27, 2017
axTLS does not correctly implement max_fragment_length extension. This
causes servers which understand this extension (currently GnuTLS- and
WolfSSL-based) to reject the client hello.

Until this is fixed in axTLS, remove the call to enable this extension
from WiFiClientSecure.

Fixes #3932.
devyte pushed a commit that referenced this issue Dec 28, 2017
…4033)

axTLS does not correctly implement max_fragment_length extension. This
causes servers which understand this extension (currently GnuTLS- and
WolfSSL-based) to reject the client hello.

Until this is fixed in axTLS, remove the call to enable this extension
from WiFiClientSecure.

Fixes #3932.
@kapyaar
Copy link
Author

kapyaar commented Jul 18, 2018

@devyte I came back to this issue, and saw that #4033 fixes this issue. I am currently using 2.4.1 latest release, and I checked my libraries/ESP8266WiFi/src/WiFiClientSecure.cpp. The file seems to have this fix but the issue persists.

Connecting to :mail.smtp2go.com:25
ssl->need_bytes=8301 > 6859

Am I missing anything? Any other changes that I have to make?

@devyte
Copy link
Collaborator

devyte commented Jul 18, 2018

  1. Relase 2.4.1 has several known issues that have since been fixed in latest master branch. Try latest git instead.
  2. I'm not sure exactly how gsender works, but I see a returned pointer to an instance, and it never gets freed. Beware mem leaks.
  3. The axtls secure lib has a long list of known issues. It is no longer maitained by the authors, so bearssl was integrated to replace it. The axtls is still the default, b ecause bearssI is still experimental, but I strongly suggest studying the bearssl examples to try and get gsender to use the bearssl::wificlientsecure instead of the normal wificlientsecure that uses axtls.

@devyte
Copy link
Collaborator

devyte commented Jul 18, 2018

To be explicit, axtls is planned for deprecation and then retirement, so issues with it won't be fixed. OTOH, if you find a problem with bearssl, please open a new issue and add the details per the issue template.

@kapyaar
Copy link
Author

kapyaar commented Jul 22, 2018

@devyte got it working with bearSSL. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants