How to send an email once an Expert Advisor places a trade?

 
I can send a test email fine from mt4. 

But I would like an email once an Expert Advisor places a trade. Is there a little line of code I could include in the EA. I would just like the subject of the email to be the pair traded, buy or sell and price traded. 

Then another email would go when the EA closes with the pair traded and exit price.

I have looked here and elsewhere before posting this but I can't find the answer. Most focus on how to send email in mt4 generally. I've managed that.

Thanks in anticipation
 
Ali irwan:
I can send a test email fine from mt4. 

But I would like an email once an Expert Advisor places a trade. Is there a little line of code I could include in the EA. I would just like the subject of the email to be the pair traded, buy or sell and price traded. 

Then another email would go when the EA closes with the pair traded and exit price.

I have looked here and elsewhere before posting this but I can't find the answer. Most focus on how to send email in mt4 generally. I've managed that.

Thanks in anticipation

You can check the return value of OrderSend() function and if it is true, you call the SendMail() Function to send out the email.

The same can be done with the OrderClose() function, but not if the SL/TP levels are hit in that case you did not use OrderClose() function,

But in that case you can still detect those closed orders by monitoring OrdersTotal() function and whenever something changes still send out the message.

https://www.mql5.com/en/docs/common/sendmail

Documentation on MQL5: Common Functions / SendMail
Documentation on MQL5: Common Functions / SendMail
  • www.mql5.com
Common Functions / SendMail - Reference on algorithmic/automated trading language for MetaTrader 5
 

MT4 platform have an option for you to input your email server.

It should send you an email whenever a trade is made on your account.

 You don't need to make an EA to send you email. 

 

 

 
Marco vd Heijden:

You can check the return value of OrderSend() function and if it is true, you call the SendMail() Function to send out the email.

The same can be done with the OrderClose() function, but not if the SL/TP levels are hit in that case you did not use OrderClose() function,

But in that case you can still detect those closed orders by monitoring OrdersTotal() function and whenever something changes still send out the message.

https://www.mql5.com/en/docs/common/sendmail

after I put the above functions, do I have the setting to serve email
 
Cuong Truong:

MT4 platform have an option for you to input your email server.

It should send you an email whenever a trade is made on your account.

 You don't need to make an EA to send you email. 

 

 

I've done the above options by entering the email server but it still can not be sent to email
 
Ali irwan:
after I put the above functions, do I have the setting to serve email

What do you mean?

You check the return value of OrderSend() function if it was successful it returns the ticket number.

int ticket=OrderSend(....

 if(ticket>0)
  {
   SendMail(....
  }


Reason: