• AVR Freaks

Helpful ReplyHot!PIC32MZ SMTPC: Can't send mail

Page: 12 > Showing page 1 of 2
Author
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
2019/05/14 08:10:46 (permalink)
0

PIC32MZ SMTPC: Can't send mail

Hi guys,
 
i'm developing a web application that need to send an email when a html button is pressed. So i created my own function that send a specific mail when is called. Unfortunately the TCPIP_SMTPC_MailMessage() callback returns me a TCPIP_SMTPC_RES_SKT_OPEN_ERROR (failure to open a communication socket). I have checked all the parameters and they seem to be ok.
I'm using a gmail account, the port is 587 using TLS, (i have enabled WolfSSL in Harmony).
 
Here is my code:
TCPIP_SMTPC_MESSAGE_RESULT mailNotRes;
static TCPIP_SMTPC_MESSAGE_HANDLE mailNotHandle = 0;

// Mail Callback
static void mailCallback(TCPIP_SMTPC_MESSAGE_HANDLE messageHandle, const TCPIP_SMTPC_MESSAGE_REPORT* pMailReport)
{
    if(pMailReport->messageRes < 0)
    {
        // Error Sending Mail occurred
        // pMailReport->messageRes return TCPIP_SMTPC_RES_SKT_OPEN_ERROR
    }
}

void test_SendMail(void)
{
    TCPIP_SMTPC_MAIL_MESSAGE mySMTPMessage;

    // Create Mail
    memset(&mySMTPMessage, 0, sizeof(mySMTPMessage));
    mySMTPMessage.body = "Some mail thex here";
    mySMTPMessage.bodySize = strlen(mySMTPMessage.body);
    mySMTPMessage.smtpServer = "smtp.gmail.com";
    mySMTPMessage.serverPort = 587;
    mySMTPMessage.username = "myemail@gmail.com";
    mySMTPMessage.password = "password";
    mySMTPMessage.to = "receiver@gmail.it";
    mySMTPMessage.from = "\"HELLO\" <sender@gmail.com>";
    mySMTPMessage.subject = "Test Mail SMTP";

    // Set a callback
    mySMTPMessage.messageCallback = mailCallback;

    // Set extra flags
    mySMTPMessage.messageFlags = TCPIP_SMTPC_MAIL_FLAG_CONNECT_TLS; // Use TLS
    mySMTPMessage.messageFlags |= TCPIP_SMTPC_MAIL_FLAG_FORCE_AUTH; // Force Authentication

    // Send
    mailNotHandle = TCPIP_SMTPC_MailMessage(&mySMTPMessage, &mailNotRes);
    if(mailNotHandle == 0)
    {
        // Some error occurred,
        // this never occur for me.
    }
    else
    {
        // So far so good
    }
}

 
My Gmail account is activated and can send mails.
 
Anyone have suggestions about this situation?
post edited by Davide33 - 2019/05/14 08:36:19
#1
rainad
Super Member
  • Total Posts : 1176
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/14 09:08:47 (permalink)
0
Using the TCPIP_SMTPC_MAIL_FLAG_CONNECT_TLS flag forces the SMTPC to open an encrypted socket from the very beginning (as opposed to doing so only when the server requests it, as part of the negotiation, which is the normal/default approach).
First, try to remove that flag. That will take you probably further on.
However, since you try to connect with gmail, the encryption will be needed after the handshake with the server is done. Most likely you'll get another error later on.
This may mean that the NET_PRES is not configured properly, or is not connected with wolfSSL as a provider, etc. One solution would be to start with a project that you know that is already configured properly and works fine with wolfSSL, like the web_net_server_nvm_mpfs.
 
 
#2
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/15 00:57:58 (permalink)
0
Thanks you for your reply!
 
I have tried to remove all the flags, so now:
mySMTPMessage.messageFlags = 0;

 
But as you had expected, i have another error: the callback now returns: 
pMailReport->messageRes = TCPIP_SMTPC_RES_SERVER_TMO

 
This is very strange to the gmail server to not respond..
 
This part isn't very clear to me:
This may mean that the NET_PRES is not configured properly, or is not connected with wolfSSL as a provider, etc.

What i need to do to configure it properly? Harmony doesn't do it itself?
post edited by Davide33 - 2019/05/15 06:14:46
#3
rainad
Super Member
  • Total Posts : 1176
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/15 06:41:02 (permalink)
0
Maybe something else is going on. Probably wireshark would be useful.
Another thing you can do is to enable the debug messages in smtpc_private.h:
#define TCPIP_SMTPC_DEBUG_LEVEL (0x1f)
and you'll have the SMTPC activity displayed on the console.
 
But first try connecting to smtp.gmail.com from your PC, using a standard networking tool, as in this shot below. That will tell you that at least that part is working fine.
 

Attached Image(s)

#4
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/15 07:20:39 (permalink)
0
Thank you very much for your support!
 
i have tried to connect to smtp.gmail.com from my pc using PuTTY. But i'm not sure what i'm doing, i only know that when i tried to send "starttls" command the program has closed after a couple of seconds.
 

 
Then the debug is attive, TCPIP_SMTPC_DEBUG_LEVEL is TCPIP_SMTPC_DEBUG_MASK_BASIC (0x0001).
But when i open the console (i use HyperTerminal on port 23) doesn't appear nothing.. This is the situation i attach the Capture2 png.
 
Forgive me but i'm in trouble.
post edited by Davide33 - 2019/05/15 07:23:11

Attached Image(s)

#5
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/15 07:49:46 (permalink)
0
I have found something strange, debugging the code, after TCPIP_SMTPC_MailMessage() has returned and after some seconds, the code stop in this row: (can't say with precision what execute before that because the code do a lot of things)
 
__reset_switch_isa:
jal _startup
nop

 
I'm a little bit confused because before removing the 2 flags, this never occur. In fact if i re-add the flags this don't occur...
post edited by Davide33 - 2019/05/15 07:53:03
#6
rainad
Super Member
  • Total Posts : 1176
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/15 10:44:53 (permalink) ☄ Helpfulby Davide33 2019/05/16 07:24:16
5 (1)
1. The execution branching at reset that you see is just as a result of the exception that happens when SMTP tries to start TLS but the provider code (i.e. wolfSSL) is not linked in.
I  remember that there was recently a fix for that in the net_pres.c, function NET_PRES_SocketEncryptSocket.
You can update your code with this addition:
 
bool NET_PRES_SocketEncryptSocket(NET_PRES_SKT_HANDLE_T handle)
{
NET_PRES_SocketData * pSkt;
if ((pSkt = _NET_PRES_SocketValidate(handle)) == NULL)
{
return false;
}
if ((pSkt->socketType & (NET_PRES_SKT_UNENCRYPTED | NET_PRES_SKT_ENCRYPTED)) != NET_PRES_SKT_UNENCRYPTED)
{
return false;
}
// add->
if(pSkt->provObject->fpInit == 0 || pSkt->provObject->fpOpen == 0 || pSkt->provObject->fpIsInited == 0)
{ // cannot start negotiation
return false;
}
// ->end add
pSkt->socketType ^= NET_PRES_SKT_UNENCRYPTED | NET_PRES_SKT_ENCRYPTED;
pSkt->status = NET_PRES_ENC_SS_WAITING_TO_START_NEGOTIATION;
return true;
}
 
See if this fixes the issue, you shouldn't get any more exceptions.
 
The telnet console won't work in this case because the debug messages go to the sys_console, which is usually the serial console and no redirection takes place to telnet. Telnet can be used to give commands, etc.
So please enable a serial console in your demo, then we'll see the debug messages.
 
Anyway, it seems that you don't have the wolfSSL linked in as a encryption provider.
As mentioned before, start from a demo app that already has that, and then things will start to work.
 
 
 
 
#7
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/16 00:32:13 (permalink)
0
Thank you very much, you are a angel Smile: Smile
 
I have added your code and the situations has changed, now the reset execution is vanished.
Now the callback is giving me TCPIP_SMTPC_RES_SKT_TLS_ERROR.
 
Now i need to link wolfSSL code? if yes can please tell me what is the method?
 
I have tried to upload in pic32 the web_net_server_nvm_mpfs code, i see a flashing green led on the board but i can't connect to the IP...
#8
rainad
Super Member
  • Total Posts : 1176
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/16 06:30:55 (permalink)
0
Try to connect to the board running the http_net_web_server_nvm_mpfs with your browser using https://board_address
This should work and should validate that the wolfSSL is present and the encryption is handled properly.
Then add your SMTP stuff to this demo.
You can open the MHC for this project and see how the wolfSSL is added to the project and configured.
 
 
#9
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/16 07:15:05 (permalink)
0
Ok, i have loaded the project and this is the result:
There is some problem with SSL certificate..
Also i didn't understand how to link wolfSSL with SMTPC, i have checked in MHC and the cofiguration of wolfSSL is equal to the other project config.
Maybe need some other changes?
 
Thanks.
post edited by Davide33 - 2019/05/16 07:22:27

Attached Image(s)

#10
rainad
Super Member
  • Total Posts : 1176
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/16 09:49:47 (permalink)
0
You should click on the "Proceed to the 10.70.1.122".
The server complains because it cannot validate the certificate, which is locally generated.
Anyway, that means that  you have the woolfSSL running fine on your board.
You can move ahead and add the SMTP code now.
 
 
#11
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/20 00:49:52 (permalink)
0
Ok thanks, but there is a problem, when i click to "Proceed to the 10.70.1.22" the page doesn't load and at the end the server respond: 

This site can’t be reached

10.70.1.22 took too long to respond.
 
I have never touched this example, is very strange that didn't work, what can i do? Should i re-download the example? if yes, you can tell me where i can found it?
#12
qhb
Superb Member
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/20 05:11:37 (permalink)
0
I've never used this stuff, but I note that rainad said:
"Proceed to the 10.70.1.122".
but you went to "10.70.1.22"
 
Does one of you have a typo?
 

Nearly there...
#13
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/20 05:21:37 (permalink)
0
Hi, thanks for your reply,
 
but i think rainad was wrong to write, because according to #10 reply the IP assigned to my pic32 board is 10.70.1.22.
#14
rainad
Super Member
  • Total Posts : 1176
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/20 10:58:03 (permalink)
0
The project as it is, out of the box, works for me. You can start with a clean copy from the Harmony distribution.
But have you tried the SMTPC now, what response did you get?
 
#15
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/21 01:32:44 (permalink)
0
Can you link me to this "Harmony distribution"? Sorry for the question but i have searched in google for microchip examples but i don't found nothing.
 
Yes, i have tried the SMTPC after your fix in post #7 and now it returns to me this error: TCPIP_SMTPC_RES_SKT_TLS_ERROR
 
Thanks for the help again.
#16
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/21 07:07:49 (permalink)
0
Update: i confirm that is a problem with wolfSSL configuration, because i have tried it with aspmx.l.google.com on port 25 in no-auth mode and it works fine, i can send mails!
 
What can i do to fix the wolfSSL configuration?
#17
rainad
Super Member
  • Total Posts : 1176
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/21 07:12:20 (permalink)
0
When I mentioned the Harmony distribution, I meant the official Harmony framework that you download from the Microchip web site. That's where you got your Harmony framework code in the first place I assume. So use the web_net_server_nvm_mpfs as a starting point, because that one has the wolfSSL properly configured and it works.
Add to that demo the SMTP part that you use. Remove from it the parts that you don't use.
 
#18
Davide33
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/03/29 06:04:47
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/21 07:22:48 (permalink)
0
Ok thanks rainad!
 
And with the wolfSSL configuration/integration maybe did you know other helpful tips?
#19
rainad
Super Member
  • Total Posts : 1176
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: PIC32MZ SMTPC: Can't send mail 2019/05/21 10:32:45 (permalink)
0
The web_net_nvm_mpfs project has the wolfSSL configured properly and it should work. That's why I think it's a good starting point. You can take a look to see what crypto algs are enabled, how the certificates are selected, how the connection with the TCP/IP stack is enabled, etc.
For specific wolfSSL questions take a look at wolfSSL.com.
 
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5