[Advanced Topic] Send eMail using DLL

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

[Advanced Topic] Send eMail using DLL

Postby mefTrader » 08 Jul 2011

Hi,

Has anyone tried to incorporate a SendMail DLL with MC? Pager_Send is not available a was on TS and RunCommand (shel command) does not seem to be available either?

Thanks
Morgan

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Send Mail DLL with MC

Postby furytrader » 08 Jul 2011

That's an interesting question. Can you give an example of how you'd use RunCommand? From what I understand, it can be used to run a command line instruction or a macro from within an EasyLanguage study.

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: Send Mail DLL with MC

Postby mefTrader » 08 Jul 2011

easylangage code :

Code: Select all

MyCommand = "C:\MyTSmails\bmail -s smtpserver.isp.com -t peter@tm.com -f peter@tm.com ...........";
RunCommand(".run " + MyCommand);
bmail.exe is a lean smtp server utility

trying to use this in Place of 'Pager_Send' that was available on TS

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Send Mail DLL with MC

Postby furytrader » 09 Jul 2011

I'm not sure if the following would help, but it's worth a shot.

Using FreeBasic, I created a simple .dll that allows you to send commands to the Windows command shell. I then created an EasyLanguage function that allows you to pass a string to this .dll which represents the full command you want the shell to execute. The EasyLanguage function I created is called "callShell".

So, for example, if you wanted to display a text document listing all the reasons you shouldn't short AAPL when its RSI hits 80 or higher, you would use the following line of EasyLanguage code (let's imagine that these reasons are contained in a file called "c:\AppleReasons.txt"):

Code: Select all

If RSI(C,13) >= 80 Then value1 = callShell("NotePad.exe c:\AppleReasons.txt");
The term "value1" in the code above is simply a throw-away variable that isn't used for anything, but is used as part of the coding convention for calling functions in EasyLanguage. Otherwise, that's all there is to it.

Attached is a .zip file that contains the following files:

1) "callShellExt.dll" - This is the .dll. This should be saved at your c:\ drive level (i.e., as "c:\callShellExt.dll"). The EasyLanguage function references this specific file location. If, for some reason, you wanted to save the .dll somewhere else, make sure to change the file reference in the EasyLanguage function below.

2) "ShellELFiles.pla" - These are two EasyLanguage files, the first being the function ("callShell") and the second being an indicator ("ShellTest") which tests the function.

3) "ConsoleTest.exe" - This is a simple Windows console application that I wrote which will receive parameters from the shell and list them when it is run (hit ENTER to close this program). It should be saved as "c:\ConsoleTest.exe" - again, you don't need this program to actually use the function; it's supplied simply for debugging purposes so you can test your code to make sure it is calling the function correctly.

4) "callShellExt.bas" - This is the FreeBasic code that was used to create the .dll. You don't need this to actually run the function, but I thought you might like to see how things work 'under the hood'.

NOTE: Because you're futzing with the shell and passing information to external programs, there's always the chance something could go wrong. I strongly recommend that you experiment with this function during off-market hours so you can make sure it works the way you want. As I was debugging this program (which, admittedly, is very simple), I crashed MultiCharts several times. I believe it works correctly now (I ran several tests and it worked fine) but I don't guarantee it. Use it at your own risk.

Also, note that the Windows command shell is very powerful, and can be called to do horrible things like format disks and delete files. Again, use at your own risk.

Good luck and let me know if this works.
Attachments
ShellFiles.zip
(9.3 KiB) Downloaded 1114 times

tekram
Posts: 96
Joined: 26 May 2009
Has thanked: 6 times
Been thanked: 18 times

Re: Send Mail DLL with MC

Postby tekram » 09 Jul 2011

I'm not sure if the following would help, but it's worth a shot. ...
Also, note that the Windows command shell is very powerful, and can be called to do horrible things like format disks and delete files. Again, use at your own risk.

Good luck and let me know if this works.
Thank you for this and this did work for a while with command line email such as bmail. However, it is not very stable and after testing about 20-30 tries (using both shell-bmail and Shelltest), callShellExt.dll seemed to freeze and the indicator will stall at "calculating" and MC became unresponsive (see attached picture). Bmail did continue to work directly in a command window, without going through callShellExt.

Image
Attachments
ShellTest Calculating 2011-07-09.gif
(13.64 KiB) Downloaded 4426 times

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Send Mail DLL with MC

Postby furytrader » 09 Jul 2011

For this application, how often do you expect to generate emails? Is it on every bar (or every tick) or just a few times a day?

tekram
Posts: 96
Joined: 26 May 2009
Has thanked: 6 times
Been thanked: 18 times

Re: Send Mail DLL with MC

Postby tekram » 09 Jul 2011

For this application, how often do you expect to generate emails? Is it on every bar (or every tick) or just a few times a day?
Thanks. I counted 17 strategy fills in my TS Filled Orders emails alerts for 7/8/11, so around 20 is a reasonable number - edited: These are not intrabar generated signals.

Thanks for writing callShellExt. Upon further testing, callShellExt seems to be fairly stable and suitable for command line functions such as programmatic sending of emails. Signals as closely timed as a few seconds do not seem to crash it, although as shown in the post above, it did freeze MC once.

Image
Attachments
MC_Gmail2011-07-09.gif
(3.76 KiB) Downloaded 4394 times

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Send Mail DLL with MC

Postby furytrader » 10 Jul 2011

I think one area where things can get tricky when it comes to launching other programs is the idea of synchronous vs. asynchronous execution.

With a synchronous execution, the program that executes the second program waits for that second program to finish before continuing. With an asynchronous launch, the launching program just goes on its merry way after launching the other program. It's not hard to imagine how a synchronous execution could gum up the subsequent functionality of MultiCharts or any other program.

When you use shell commands, you can tell Windows whether to launch something synchronously or asynchronously. To tell Windows to execute a second program asynchronously, you use the "START" command as part of the overall command string you send to the shell - for example,

"START Notepad.exe c:\AppleReasons.txt" (using my example from my earlier post)

In Windows XP SP2 and afterwards, the "Start" shell command has a lot of additional features (for example, it doesn't have to open up a console window, you can change the priority of execution, etc.) From the Windows command line, type in "START /?" to get a run-down of all the features of this command.

I think if you were to try to run your program asynchronously, it will lead to more stable results. I haven't tested this idea, and I'm not a professional programmer, so I may be wrong, but that's what my intuition tells me.

Anyway, good luck!

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: Send Mail DLL with MC

Postby mefTrader » 10 Jul 2011

Code: Select all

//msg = " START c:\blat -install <smtp mail server here> <mail id> - <port> - <username> <passwd>";
msg = " START c:\blat -to <user1@gmail.com>,<user2@gmail.com> -subject "+DoubleQuote+"Email from MC"+DoubleQuote+" -body "+DoubleQuote+"If you get this then great!"+DoubleQuote;

if Date = 1110708 then value1 =callShell(msg);
Rather than using bmail looked at using blat.exe instead 'cause I needed authentication...

the commented out 'msg' was used 1st to install blat using my server settings

then I commented it out and used the 2nd message (shown here) to send a message successfully....

agree with using START .. probably sending asynchronously would be best....

Need to send emails over 40 instruments on a n hourly basis - so I have not tried that yet but will give feedback if I see anything strange!

This seems to be a workaround for Pager_Send at least...

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: Send Mail DLL with MC

Postby mefTrader » 10 Jul 2011

Here is the link for blat

http://www.fatwallet.com/forums/technology/667875/

(upd: the link is no longer functional. See why here)

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: Send Mail DLL with MC

Postby mefTrader » 11 Jul 2011

Seems to be working quite well on an active EOD/Intra Day system (Medium Frequency system) for me

flyscalper
Posts: 14
Joined: 01 Jan 2012
Has thanked: 4 times

Re: Send Mail DLL with MC

Postby flyscalper » 18 Jan 2012

For this application, how often do you expect to generate emails? Is it on every bar (or every tick) or just a few times a day?
Thanks. I counted 17 strategy fills in my TS Filled Orders emails alerts for 7/8/11, so around 20 is a reasonable number - edited: These are not intrabar generated signals.

Thanks for writing callShellExt. Upon further testing, callShellExt seems to be fairly stable and suitable for command line functions such as programmatic sending of emails. Signals as closely timed as a few seconds do not seem to crash it, although as shown in the post above, it did freeze MC once.

Image
This is very interesting. I am looking for a way to send an email whenever I get an order filled. Do you think it is possible in Multicharts? In other plattforms that is quite straightforward...

Un saludo,

Pablo

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: Send Mail DLL with MC

Postby mefTrader » 20 Jun 2012

I'm not sure if the following would help, but it's worth a shot.

Using FreeBasic, I created a simple .dll that allows you to send commands to the Windows command shell. I then created an EasyLanguage function that allows you to pass a string to this .dll which represents the full command you want the shell to execute. The EasyLanguage function I created is called "callShell".

So, for example, if you wanted to display a text document listing all the reasons you shouldn't short AAPL when its RSI hits 80 or higher, you would use the following line of EasyLanguage code (let's imagine that these reasons are contained in a file called "c:\AppleReasons.txt"):

Code: Select all

If RSI(C,13) >= 80 Then value1 = callShell("NotePad.exe c:\AppleReasons.txt");
The term "value1" in the code above is simply a throw-away variable that isn't used for anything, but is used as part of the coding convention for calling functions in EasyLanguage. Otherwise, that's all there is to it.

Attached is a .zip file that contains the following files:

1) "callShellExt.dll" - This is the .dll. This should be saved at your c:\ drive level (i.e., as "c:\callShellExt.dll"). The EasyLanguage function references this specific file location. If, for some reason, you wanted to save the .dll somewhere else, make sure to change the file reference in the EasyLanguage function below.

2) "ShellELFiles.pla" - These are two EasyLanguage files, the first being the function ("callShell") and the second being an indicator ("ShellTest") which tests the function.

3) "ConsoleTest.exe" - This is a simple Windows console application that I wrote which will receive parameters from the shell and list them when it is run (hit ENTER to close this program). It should be saved as "c:\ConsoleTest.exe" - again, you don't need this program to actually use the function; it's supplied simply for debugging purposes so you can test your code to make sure it is calling the function correctly.

4) "callShellExt.bas" - This is the FreeBasic code that was used to create the .dll. You don't need this to actually run the function, but I thought you might like to see how things work 'under the hood'.

NOTE: Because you're futzing with the shell and passing information to external programs, there's always the chance something could go wrong. I strongly recommend that you experiment with this function during off-market hours so you can make sure it works the way you want. As I was debugging this program (which, admittedly, is very simple), I crashed MultiCharts several times. I believe it works correctly now (I ran several tests and it worked fine) but I don't guarantee it. Use it at your own risk.

Also, note that the Windows command shell is very powerful, and can be called to do horrible things like format disks and delete files. Again, use at your own risk.

Good luck and let me know if this works.
furytrader is this a 32bit dll ? can it work with 64bit MC ?

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Send Mail DLL with MC

Postby furytrader » 20 Jun 2012

It was written using FreeBasic so I am guessing it's a 32-bit DLL. I have not tried to use it with MC 64-bit yet. The code of the dll itself is very simple - it simply executes a shell command - so reproducing it in a 64-bit environment shouldn't be too hard.

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: Send Mail DLL with MC

Postby mefTrader » 20 Jun 2012

When someone generates the 64 bit version can they post it here please? Thanks

brendanh
Posts: 158
Joined: 07 Apr 2007
Has thanked: 1 time

Re: [Advanced Topic] Send Mail DLL with MC

Postby brendanh » 14 May 2013

Is there the ability to run a shell command from MultiCharts 64bit code yet (non .Net)?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: [Advanced Topic] Send Mail DLL with MC

Postby Henry MultiСharts » 15 May 2013

Is there the ability to run a shell command from MultiCharts 64bit code yet (non .Net)?
Here is a function and an indicator that will run Windows Calculator once the study is applied to the chart. For more information on ShellExecute function please refer to MSDN.
Attachments
ShellExecute.pla
(3.94 KiB) Downloaded 901 times


Return to “User Contributed Studies and Indicator Library”