Skip to content

SendEmail Method

SendEmail

Summary

Sends a notification email message.

Remarks

This method doesn't work during backtesting and optimization.Use correct settings before trying to send an email notification.You can do that in Preferences -> Email Settings

Signature

1
public abstract void SendEmail(string from, string to, string subject, string text)

Parameters

Name Type Description
from string Sender's Address
to string Recipient's Address
subject string Email Subject
text string Email Body

Return Value

void

Declaring Type

cAlgo.API.Internals.INotifications

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 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.None)]
     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);
             }
         }
     }
 }

Last update: November 25, 2022

Comments