Email alerts problem
Email alerts problem
07 Feb 2025, 13:28
I've tested the following code to send emails, but throws errors of authentication (Authentication with SMTP server failed). In my gmail account I've selected it was my authentication but nothing changes. What's wrong?
My gmail settings:
//--------------------------------------------------
Server: smtp.gmail.com
Port: 587 or 465
Username: xxxxxxxxxxxxxx@gmail.com
Password: mypassword
//---------------------------------------------------
The code:
using cAlgo.API;
namespace cAlgo
{
// This sample indicator shows how to use API notifications to play sound or send an email
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class NotificationsSample : Indicator
{
private int _lastNotifiedBarIndex;
[Parameter("Sound File Path", DefaultValue = "C:\\Windows\\Media\\notify.wav")]
public string SoundFilePath { get; set; }
[Parameter("Sender Email")]
public string SenderEmail { get; set; }
[Parameter("Receiver Email")]
public string ReceiverEmail { get; set; }
protected override void Initialize()
{
}
public override void Calculate(int index)
{
if (!IsLastBar || _lastNotifiedBarIndex == index) return;
_lastNotifiedBarIndex = index;
if (Bars.Last(1).Close > Bars.Last(1).Open)
{
Notify("Up Bar Closed");
}
else if (Bars.Last(1).Close < Bars.Last(1).Open)
{
Notify("Down Bar Closed");
}
}
private void Notify(string message)
{
if (!string.IsNullOrWhiteSpace(SoundFilePath))
{
Notifications.PlaySound(SoundFilePath);
}
if (!string.IsNullOrWhiteSpace(SenderEmail) && !string.IsNullOrWhiteSpace(ReceiverEmail))
{
Notifications.SendEmail(SenderEmail, ReceiverEmail, "Notification", message);
}
}
}
}
firemyst
23 Feb 2025, 08:31
Did you follow the instructions here for setting up your gmail account?
https:// help . ctrader . com /ctrader-algo/email-notifications/#sending-notifications-programmatically
@firemyst