Syntax
public static void SendEmail(this EmailAlertParams param, string To, string MessageSubject, string MessageText)
public EmailAlertParams(string from, string smtpServer, int port, string login, string pass, bool secure)
public AlertByEmail( string from, string smtpserver, int port, string pass, bool secure )
public void SendEmail( string To, string Subj, string Msg )
Parameter Description
param | An EmailAlertParams instance with STMP server parameters |
from | Sender E-mail address |
smtpServer | SMTP server |
port | SMTP server port |
pass | SMTP server password |
secure | Secure connection (true = enabled, false = disabled) |
(optional) login | Use this only when your SMTP login is different from your email address. |
To | Destination e-mail address |
MessageSubject | Message subject |
MessageText | Message body |
Description
Note: Wealth-Lab 6 has Email Alerts natively. Open
Preferences - Email Alerts to set up your email account and start receiving Strategy alerts. "AlertByEmail" helps you send customized messages.
By virtue of .NET, it's possible to send e-mail in WL6 from the Strategy code. This code illustrates how to do it using a secure (SSL) mail server (e.g. Google).
First, create an instance of the EmailAlertParams class in the Strategy code like shown below, passing the essential parameters like sender e-mail and SMTP server credentials and port. Then call SendEmail, passing destination e-mail address and the message subject and text.
Note: if using Gmail, you might need to
Allow less secure apps to access your account.
Effective February 15, 2021, AlertByEmail will stop working for G Suite accounts (ex Google Apps for Domains) because Google will retire access for Less Secure Apps on that date.
Example
Example using C# extension methods:using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class TestEmail : WealthScript
{
protected override void Execute()
{
string From = "your.email@gmail.com";
string SmtpServer = "smtp.gmail.com";
int Port = 587;
string Pass = "yourpassword";
bool Secure = true;
EmailAlertParams param = new EmailAlertParams( From, SmtpServer, Port, Pass, Secure );
param.SendEmail( "another.address@gmail.com", "Hello World!", "E-mail generated by Wealth-Lab 6" );
}
}
}
Legacy syntax example:First, create an instance of the class in the Strategy code like shown below, passing the essential parameters like sender e-mail and SMTP server credentials and port. Then call SendEmail, passing destination e-mail address and the message subject and text.
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components; /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/
namespace WealthLab.Strategies
{
public class TestEmail : WealthScript
{
protected override void Execute()
{
string From = "your.email@gmail.com";
string smtpServer = "smtp.gmail.com";
int Port = 587;
string Pass = "yourpassword";
AlertByEmail mail = new AlertByEmail( From, smtpServer, Port, Pass, true );
mail.SendEmail( "another.address@gmail.com", "Hello World!", "E-mail generated by Wealth-Lab 5" );
}
}
}