I am using SendMail() normally and get this error. I have verified by printing the strings I have passed to the the function that they are initialized properly. Funny thing is the mail is sent just fine (including the subject and the text), but when I retrieve last error via GetLastError() it returns 4008. Any ideas?
ERR_NOT_INITIALIZED_STRING | 4008 | Not initialized string; no value was assigned to the string being an operand in an expression |
Just occurred to me that maybe the GetLastError() is returning an error that happened somewhere else. Is it guaranteed that SendMail() would set the GetLastError() buffer to ERR_NO_ERROR if no error occurred during it's run, or perhaps it does not touch the buffer if no error occured, in which case my theory might be correct and the error might happen somewhere else...?
Just occurred to me that maybe the GetLastError() is returning an error that happened somewhere else.
I wondered about that, and tried it out, but didn't reply earlier because SendMail() does seem to set the last error. Though it appears to set the code to 4060 ("Function is not confirmed"), not zero.
But, nevertheless, I do wonder if your error is in fact somewhere else. I thought I'd had 4008 when passing uninitialised strings to a function which takes a string as a reference parameter, but I can't now reproduce such a problem.
I wondered about that, and tried it out, but didn't reply earlier because SendMail() does seem to set the last error. Though it appears to set the code to 4060 ("Function is not confirmed"), not zero.
But, nevertheless, I do wonder if your error is in fact somewhere else. I thought I'd had 4008 when passing uninitialised strings to a function which takes a string as a reference parameter, but I can't now reproduce such a problem.
Just checked it and it's indeed happening before. Still hunting the source though. What I find amusing is that it's specifically implied in the documentation that SendMail() will reset the GetLastError() buffer if no error occurred... From the documentation (https://docs.mql4.com/constants/errors):
#include <stderror.mqh>
#include <stdlib.mqh>
void SendMyMessage(string text)
{
int check;
SendMail("some subject", text);
check=GetLastError();
if(check!=ERR_NO_ERROR) Print("Cannot send message, error: ",ErrorDescription(check));
}
Solution: have to call GetLastError() before using SendMail() to clear the error buffer.
Just checked it and it's indeed happening before. Still hunting the source though. What I find amusing is that it's specifically implied in the documentation that SendMail() will reset the GetLastError() buffer if no error occurred... From the documentation (https://docs.mql4.com/constants/errors):
Solution: have to call GetLastError() before using SendMail() to clear the error buffer.
I think ERR_NOT_INITIALIZED_STRING may occur if you declare a string as
string str;
rather than
string str="";
... and you are right that the error could have occurred well before the SendMail call.
Paul
I think ERR_NOT_INITIALIZED_STRING may occur if you declare a string as
rather than
... and you are right that the error could have occurred well before the SendMail call.
Paul
Yeah, I know, I found the cause. The surprise is that SendMail() does not set error buffer to ERR_NO_ERROR if there was no error (as implied in the documentation - see above). Anyways, thanks.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am using SendMail() normally and get this error. I have verified by printing the strings I have passed to the the function that they are initialized properly. Funny thing is the mail is sent just fine (including the subject and the text), but when I retrieve last error via GetLastError() it returns 4008. Any ideas?