SMTP Email Client issue

leenowell
Posts: 92
Joined: Tue Jan 15, 2019 1:50 pm

SMTP Email Client issue

Postby leenowell » Sat Jan 16, 2021 7:20 pm

Hi All,

I have a project which initialises wifi on the main thread then creates an email task which looks for messages on a queue and sends via email. The email task is the smtp_client_example code.

Sometimes this works fine but when I change unrelated code it seems to fail with "mbedtls_ssl_read failed with error -0x7200" and sometimes -0x7100. The failure is in write_ssl_and_get_response when it calls mbedtls_ssl_read.

I suspect this is a threading/ task corruption issue so wanted to check whether in principle this should be fine i.e. initialising wifi in the main thread and doing the smpt email in another? I assume that xQueueSend takes a copy of the data so where the data is stored before calling it shouldn't matter?

Thanks in advance for your help

Lee.

leenowell
Posts: 92
Joined: Tue Jan 15, 2019 1:50 pm

printf causes SMTP Email Client issue?

Postby leenowell » Sun Jan 17, 2021 8:14 am

Hi All,

Quick update. I have narrowed down a line that is causing the problem (at the moment at least) although not sure this is the root cause to be honest. I have the following line before I call the method (I wrapped the smpt sample code in a class) to send the email (which ultimately calls the write_ssl_and_get_response code)

Code: Select all

printf("sMessage[%s] strlen[%d] sizof[%d]\n",data.sMessage, strlen(data.sMessage), sizeof(data.sMessage));
data is the struct sent via the queue and is defined as

Code: Select all

typedef struct
{
	char sSubject[50];
	char sMessage[100]; 
} email_data_t;
Instantiation of data and then the call to populate it from the queue are

Code: Select all

	email_data_t data = {};
	if (xQueueReceive( emailQueue, &data, 0 ))
If I remove any one of parameters in the printf, the send email works fine, similarly, if I change printf to ESP_LOGI (keeping all parameters) it also works fine. Seems very odd so suspect in reality there is some stack corruption going on somewhere (hence my original question).

To add to the odd behaviour, I happen to then test with ESP_LOGI and using the data.sMessage seems to causes a "-0x7100 - SSL - Bad input parameters to function" error which copying the string into a calloc'd buf works fine.

This works

Code: Select all

		if (xQueueReceive( emailQueue, &data, 0 ))
		{
			ESP_LOGI("doProcessEmailMessages","Read Email Message [%s] from the queue", (char*) data.sMessage);
			char *buf = (char*) calloc(1,200);
			sprintf(buf, "%s", data.sMessage);
			printf("BUF[%s]", buf);
			ESP_LOGI("TEST", "sMessage[%s] strlen[%d] sizof[%d]\n",data.sMessage , strlen(data.sMessage), sizeof(data.sMessage));
			email.SendEmail("xxxx@yyyy.com", "Test Sender", "yyyyy@zzzz.com", "Test Subject", buf);
		}
This does not work - only change is final parameter of the sendEmail call.

Code: Select all

		if (xQueueReceive( emailQueue, &data, 0 ))
		{
			ESP_LOGI("doProcessEmailMessages","Read Email Message [%s] from the queue", (char*) data.sMessage);
			char *buf = (char*) calloc(1,200);
			sprintf(buf, "%s", data.sMessage);
			printf("BUF[%s]", buf);
			ESP_LOGI("TEST", "sMessage[%s] strlen[%d] sizof[%d]\n",data.sMessage , strlen(data.sMessage), sizeof(data.sMessage));
			email.SendEmail("xxxx@yyyy.com", "Test Sender", "yyyyy@zzzz.com", "Test Subject", data.sMessage);
		}
This is proving very tricky to debug so would appreciate any help/ thoughts.

Thanks in advance

Lee.

Who is online

Users browsing this forum: No registered users and 328 guests