
//+------------------------------------------------------------------+
 //| MailSend.mq4                                                  |
 //| Send email script based on mailsend                             |
 //| Download from:                                                  | 
 //| http://www.muquit.com/muquit/software/mailsend/mailsend.html    |
 //| much kudos to Muhammad Muquit for great work on mailsend        |
 //| Script by: rhtrader / Reckless Rich - 2/2/2013                  |
 //+-----------------------------------------------------------------+
 
 

// place mailsend.exe (or whatever the latest version is) in the MT4 root folder


#define SW_HIDE 0
#define SW_SHOWNORMAL 1
#define SW_NORMAL 1
#define SW_SHOWMINIMIZED 2
#define SW_SHOWMAXIMIZED 3
#define SW_MAXIMIZE 3
#define SW_SHOWNOACTIVATE 4
#define SW_SHOW 5
#define SW_MINIMIZE 6
#define SW_SHOWMINNOACTIVE 7
#define SW_SHOWNA 8
#define SW_RESTORE 9
#define SW_SHOWDEFAULT 10
#define SW_FORCEMINIMIZE 11
#define SW_MAX 11

#import "shell32.dll"
   int ShellExecuteA(int hWnd,string lpVerb,string lpFile,string lpParameters,string lpDirectory,int nCmdShow); 
#import

// Use as externs as required
string Email_Settings = "**** EMAIL SETTINGS ****" ;
string EmailSMTPServer ="smtp.gmail.com";
string EmailUser ="yourid@gmail.com"; 
string EmailPass="yourSMTPpassword"; 
bool   EmailUseSSL = true; // Use SSL or StartTLS or neither. Gmail requires one or the other with the correct port. 
bool   EmailStartTLS = false;
string EmailPort = "465";   //GMAIL - Port for STARTTLS: 587, Port for SSL: 465
bool   EmailAuthenticate = true; // required for GMAIL
string EmailAuthString = "-auth-login" ; // "", "-auth-plain", "-auth-login" or "-auth-cram-md5"........ "-auth-plain" or "-auth-login" used for GMAIL
string EmailFrom ="you@gmail.com"; 
string EmailToAddr ="them@xxxx.com"; 
// string EmailToAddrSMS = "+447971131692@mmail.co.uk"; // in my case I can use this for sending an SMS text to my phone

string EmailSubject = "Buy EURUSD @ 1.36434"; 
string EmailBody =""; 
string EmailCC =""; 
string EmailBCC ="";
string EmailFilterSuffix = "Filter string here" ;  // appended to subject for email filtering
string EmailAttachFileName ="experts\\files\\shots\\screenshot.gif"; // folder starts at the MT4 root folder. Ensure you use "\\" for "\" backslash in path name

int start()
{
 
   string UseSSL, UseStartTLS , AttachString, MailSendString ;  
   EmailSubject = Symbol() + " " + tf2txt(Period()) + ": " + EmailSubject + " " + EmailFilterSuffix ;
   EmailBody = EmailSubject ; // making them the same text
 
   if(EmailUseSSL) UseSSL = "-ssl" ; else UseSSL = "" ;
   if(EmailStartTLS) UseStartTLS = "-starttls" ; else UseStartTLS = "" ; 
   if(EmailAttachFileName == "") AttachString = "" ; else AttachString = "-attach \"" + EmailAttachFileName +  "\"" ;    

   MailSendString = " /c mailsend1.exe -to " + EmailToAddr + " -from " + EmailFrom + " " + UseSSL + " " + UseStartTLS + " -smtp " + EmailSMTPServer + " -port " + EmailPort + " -sub \"" + EmailSubject + "\" +cc " + EmailCC + " +bc " + EmailBCC + " -v " + " " + EmailAuthString + " -user " + EmailUser + " -pass " + EmailPass + " -M \"" + EmailBody + "\" " + AttachString  ;
   int catch = ShellExecuteA(0,"Open","cmd",MailSendString,"",SW_HIDE);

   return(0);
}

string tf2txt(int tf)
{
   if (tf == PERIOD_M1)    return("M1");
   if (tf == PERIOD_M5)    return("M5");
   if (tf == PERIOD_M15)   return("M15");
   if (tf == PERIOD_M30)   return("M30");
   if (tf == PERIOD_H1)    return("H1");
   if (tf == PERIOD_H4)    return("H4");
   if (tf == PERIOD_D1)    return("D1");
   if (tf == PERIOD_W1)    return("W1");
   if (tf == PERIOD_MN1)   return("MN");
   
   return("??");
}
/*

http://www.muquit.com/muquit/software/mailsend/mailsend.html

Synopsis 
Version: @(#) mailsend v1.16

Copyright: GNU GPL. It is illegal to use this software for Spamming

(Compiled with OpenSSL 1.0.0g 18 Jan 2012)
usage: mailsend [options]
Where the options are:
 -smtp hostname/IP*    - of the SMTP server
 -port SMTP port       - SMTP port
 -d    domain          - domain name for SMTP HELO/EHLO
 -t    to,to..*        - email address/es of the recipient/s
 -cc   cc,cc..         - Carbon copy address/es
 +cc                   - don't ask for Carbon Copy
 -bc   bcc,bcc..       - Blind carbon copy address/es
 +bc                   - don't ask for Blind carbon copy
 +D                    - don't add Date header
 -f    address*        - email address of the sender
 -sub  subject         - subject
 -l    file            - a file containing the email addresses
 -attach file,mime_type,[i/a] (i=inline,a=attachment)
                       - attach this file as attachment or inline
 -cs   character set   - for text/plain attachments (default is us-ascii)
 -M    "one line msg"  - attach this one line text message
 -name "Full Name"     - add name in the From header
 -v                    - verbose mode
 -V                    - show version info
 -w                    - wait for a CR after sending the mail
 -rt  email_address    - add Reply-To header
 -rrr email_address    - request read receipts to this address
 -ssl                  - SMTP over SSL
 -starttls             - Check for STARTTLS and if server supports, do it
 -auth                 - Try CRAM-MD5,LOGIN,PLAIN in that order
 -auth-cram-md5        - use AUTH CRAM-MD5 authentication
 -auth-plain           - use AUTH PLAIN authentication
 -auth-login           - use AUTH LOGIN authentication
 -user username        - username for ESMTP authentication
 -pass password        - password for ESMTP authentication
 -example              - show examples
 -ehlo                 - force EHLO
 -info                 - show SMTP server information
 -help                 - shows this help
 -q                    - quiet

The options with * must the specified
*/

