Failed to send email. Timeout.

Created at 26 May 2020, 18:56
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
JE

jesusoro17

Joined 26.05.2020

Failed to send email. Timeout.
26 May 2020, 18:56


Hi. I'm trying to make an algorithm to send email notifications with moving average crossovers. I'm actually learning to code, so I borrowed some code from a cBot included in ctrader. The problem is that the emails are not being sent. Everytime a crossover occurs, I get the message  "Failed to send email "Crossover". Timeout"". 

Settings: Enable Email check, Use SSL check, Server smtp.gmail.com, Port 25, Use authentication check. I configured gmail to allow the access of less secure apps.

What could be happening? I already tried with gmail, hotmail, yahoo. I even tried cockmail. The last one even seemed to work, as there was an opportunity when the cBot log said "Email succesfully sent". But the email was never sent.

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Alerts : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Allow email notifications", Group = "Email notifications", DefaultValue = true)]
        public bool IsEmailAllowed { get; set; }

        [Parameter("Slow Periods", DefaultValue = 10)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", DefaultValue = 5)]
        public int FastPeriods { get; set; }

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Message", Group = "Email notifications")]
        public string message { get; set; }

        [Parameter("Sender Email address", Group = "Email notifications")]
        public string EmailAddress { get; set; }

        [Parameter("Receiving Email address", Group = "Email notifications")]
        public string EmailAddressR { get; set; }

        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Sample Trend cBot";

        protected override void OnStart()
        {
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
        }

        protected override void OnTick()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);

            if (previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && longPosition == null)
            {
                Notifications.SendEmail(EmailAddress, EmailAddressR, message, message);
            }
            else if (previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && shortPosition == null)
            {
                Notifications.SendEmail(EmailAddress, EmailAddressR, message, message);
            }
        }
    }
}

 


@jesusoro17