Enabling SendMail() in MT5

 

I have setup Email correctly in MT5 through Tools->Options->Email and ticked the checkbox Enable. Test button in this window works fine.

However from my EA/Indicator when I use SendMail() function, emails are not sent and GetLastError() returns error - 4014 - "System function is not allowed to call". Any other setting to be done in the terminal which I have missed?

Documentation on MQL5: Common Functions / SendMail
  • www.mql5.com
Common Functions / SendMail - Documentation on MQL5
 
Further problem isolation reveals  that SendMail() function fails if calculated from OnCalculate() function. Indicator code to reproduce the problem enclosed.
//+------------------------------------------------------------------+
//|                                                 SendMailTest.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_label1 "UP !MOVE"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed

double Down1[];
int OnInit()
  {
//---
   // Initialize the indicators
   SetIndexBuffer(0, Down1, INDICATOR_DATA);
   ArraySetAsSeries(Down1, true);
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   
   string concatString1 = "Working Test";
   string concatString2 = "Working Test";
   SendMail(concatString1, concatString2);
   
//   TestFunc();
//---
   return(0);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[]) {
                
   string concatString1 = "Not Working Test";
   string concatString2 = "Not Working Test";
   SendMail(concatString1, concatString2);
   Print("Error ", GetLastError());
   
   return(rates_total);
}
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
Language Basics / Functions / Event Handling Functions - Documentation on MQL5
 
Perhaps the reason is that you are trying to send mail too fast? There might be some required delay period before SendMail() can work again.
 

Please try again in current build. It has been changed.