Using Easy Email with the fnSendEzEmail function
There are 3 methods available to send emails using the Easy Email Plug-in. Emails can be sent using:
- The Communication Manager
- Any Element
- The Toolbox function fnSendEzEmail
Note: Before any emails can be successfully sent, the Easy Email Settings must be configured.
This section describes how to use the fnSendEzEmail function to send emails.
The Communication Manager and the Element Message Tab are the easiest ways to use the Easy Email Plug-in to send emails.
This method is provided for the rare occasions when where drag and drop function control is required. Also, this technique serves as tutorial for creating and using MQL functions.
Background
The MetaTrader platform supports sending emails using a simple built-in function named SendMail.
Unfortunately, the SendMail function only works with non-secure email servers, and today almost all email providers use secure connections for sending and receiving emails.
In order to establish a secure email connection, additional code must be created to manage an SMTP connection. SMTP stands for Simple Mail Transfer Protocol and is an internet standard for sending and receiving emails.
The SMTP connection code resides in a Dynamic Link Library (DLL). (In this case, the DLL is named ezemail.dll)
For an Expert Advisor to use the functionality of a DLL, the DLL must be described and referenced in the MQL code, and the DLL must reside in the libraries folder of the MetaTrader platform.
VTS automatically copies the DLL to the libraries folder and adds all required MQL code to use the Easy Email functions.
The function fnSendEzEmail is available from the Toolbox under the Common menu. The fnSendEzEmail function is an MQL function. Because fnSendEzEmail is an MQL function, the MQL source code of this function is available from the Toolbox under the Advanced->MQL menu. The name of the MQL source code function has been changed to fnSendEzEmailMql to create a distinction between the two functions. When you create an MQL function, the name of the function within the MQL code will be the name of the function on the Advanced->MQL menu. The name of the MQL Element in which the MQL code was entered can be named any available name, for example MyMql. The function on the Advanced->MQL menu holds the MQL source code and can be edited at any time. The function MyMql represents a call to the function on the Advanced->MQL menu. It does not contain the MQL code, only a call to the underlying function with the parameters set specifically. For example, the function fnSendEzEmail can be dragged onto to the Drawing Pad, set the To parameter to a work email address and named SendEmailToWork. Another copy can be dragged onto the Pad, the To parameter set to a home email address and name SendEmailHome. More information about MQL function is described here. The parameters of the fnSendEzEmail function are described below. |
NOTE: There is no count available to control how many times an email is sent when using the fnSendEzEmail function. Care must be exercised to ensure a large number of emails are not sent.
Name |
Data Type |
Description |
Server |
string |
The smtp server name of your email provider. The smtp server name can be found by (1) asking you email provider, or (2) a simple internet search. |
UserName |
string |
This is the email address that you have with your email provider. (Note: It can also be the To Address that emails are sent to). |
Password |
string |
The password used to connect with the Email Address with your email service provider. NOTE: This password is stored as clear text. Do not use the same password that you use for high security accounts. |
Port |
integer |
The port of your email providers smtp service. For secure connections, the value is usually 465. The smtp port number can be found by (1) asking you email provider, or (2) a simple internet search. |
From |
string |
The email address that your email will show that it was sent from. Normally you do not need to set this value when you compose an email within an email program, but this field is required to create a valid email. The From address can be the same as the To address. |
To |
string |
The email address that your email will be sent to. |
Copy |
string |
Optional email address to copy your email to. |
Subject |
string |
The subject that will appear in the subject line of the email. |
Body |
string |
The body of the email (the text message). |
AttachFile |
string |
The full path of a file to be attached to the email. |