Email Return Values

Discussion to talk about software related topics only.
Post Reply
kackle123
Posts: 73
Joined: Tue Nov 23, 2010 1:35 pm

Email Return Values

Post by kackle123 »

What are the correct return values for the email functions? There is a conflict within the header files. I am using v2.5.3.

Plain email functions (mailto.h):

Code: Select all

/*-------------------------------------------------------------------
 * Send an email with plain text authentication
 * Returns 0 on failure, 1 on success
 *-------------------------------------------------------------------*/
int SendMailAuth( IPADDR smtp_server, 
                        PCSTR userid,     
                        PCSTR pass,       
                        PCSTR from_addr,  
                        PCSTR to_addr,    
                        PCSTR subject,    
                        PCSTR textbody );

// Error codes
#define STATUS_OK                      (0)
#define CONNECT_TO_SMTP_SERVER_FAILED  (-1)
And the encrypted email functions (ssl_mailto.h):

Code: Select all

int SSL_SendMail( IPADDR smtp_server, 
                         PCSTR userid,           
                         PCSTR pass,          
                         PCSTR from_addr,     
                         PCSTR to_addr,       
                         PCSTR subject,       
                         PCSTR textbody,     
                         BOOL STARTTLS = FALSE );

// Returns 0 or error code

// SMTP error codes
#define STATUS_OK                      (0)
#define CONNECT_TO_SMTP_SERVER_FAILED  (-1)
So which is right, success == 0, 1, -1, or other? I think I have received a 1 == success using the encrypted functions in the past, but I am having trouble emailing now, and I must rule out the NB tools before I point fingers elsewhere.
Last edited by kackle123 on Fri Apr 25, 2014 6:14 am, edited 1 time in total.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Email Return Values

Post by rnixon »

I think there are two separate ways of reporting - the return value and a mail logging system since there are so many transactions. You have the source as well, so you can take a look to see what is going on. It would also be a good idea to experiment - did you try to send and print out the return value on one that was successful?

What I see at the end of the ssl function source is:

NB_Mail_Error_Code = STATUS_OK;
siprintf(NB_Mail_Error_String, "Mail Transaction completed successfully.\r\n");
MAILDBPRINT( DB_MAIL, "Mail complete\r\n" );

return 1;
}

I don't have a running app to check, but it looks like there is both an error code variable, and a return value.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Email Return Values

Post by rnixon »

Just looked at the runtime manual (should have done that first!). Page 209 describes this in detail.
kackle123
Posts: 73
Joined: Tue Nov 23, 2010 1:35 pm

Re: Email Return Values

Post by kackle123 »

rnixon, thank you for your reply.

I don't have the PDF manual to look through because the original cryptography library manual was missing the email entries. I can't download a new manual version because I have no support contract with NB currently. I have requested one from the sales department.

I couldn't experiment with the function because SSL_SendMail() sometimes returns 1, sometimes not, though the email always gets sent to the recipient. (I assume there is something amiss with our company's email server.) So I couldn't know which return value was proper.

I didn't know or forgot I had the source code. Thanks for pointing that out. I looked through the source ("ssl_mailto.cpp") and I agree; it looks like 1 == success. The header was confusing to me as it describes two different "status values". One status value must be for the function's return, and the other for some sort of internal error output ("NB_Mail_Error_Code"). I will go with 1 == success.

Thank you again.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Email Return Values

Post by rnixon »

When you say sometimes it does not return 1 , exactly what does it return?

The other variable isn't some internal variable, its a log so you can see the entire transaction. Sounds like that could be very useful to you in debugging this.
kackle123
Posts: 73
Joined: Tue Nov 23, 2010 1:35 pm

Re: Email Return Values

Post by kackle123 »

Honestly I don't know what the function returns because my code has been:

Code: Select all

if(SSL_SendMail() != 1) { // Error. }
I would quickly check its return now but, alas, the problem is rather intermittent. However, printing out one of the "internal variables" (NB_Mail_Error_Code) after a failed email attempt once yielded a -7 or a "DATA_END_SERVER_REPLY_FAILED". If I understand this, at the end of my message body, my NB board sends "\r\n", then ".", then "\r\n", and then waits for an SMTP "250" returned back from the email server. It must time out waiting for that 250 (> 4 seconds?).

According to the email server logs, the 250 is sent to the NB board (even during the failures) waaay before 4 seconds has elapsed, so I am a little puzzled right now.

Oh, and yes, I will look further into using those "transaction variables".
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Email Return Values

Post by rnixon »

The email example SendMail shows you exactly how to display the entire transaction log in the void LastResult( int sock, PCSTR url ) function.
kackle123
Posts: 73
Joined: Tue Nov 23, 2010 1:35 pm

Re: Email Return Values

Post by kackle123 »

I used PrintNBError() and PrintServerLog() to display the entire email transaction, but they didn't tell me anything I didn't already know-the transaction is dying during the DATA block. That is, the NB board is sending the terminating "." to the email server, but the board times out before it gets the 250 reply from the server. (I now don't trust that our IT department gave me the correct email server transaction log for the failed email attempts in the first place...)

Anyway, I tried changing the timeout time to 30 seconds (within "ssl_mailto.cpp"), and the failures significantly reduced. I think that sometimes that DATA step takes much longer than 4 seconds; according to RFC 5321, that timeout should be 10 MINUTES! That's apparently because the server (some servers?) is accepting responsibility that the email will be delivered, no matter what. So, I'm guessing the server actually tries to deliver the message to the end recipient's server before responding with the 250. In some cases, this may take more than 4 seconds, especially if there must be some DNS resolution done first. (This correlates with my observation that emailing certain recipients/domains had significantly more -7 failures than others.)

I think the NB people should be made aware of this, but I no longer have a support contract with them, so I don't know how to communicate this except by posting it here.
Post Reply