Is it possible to send an email when the bot stops with an error?

bambinou

Client
Регистрация
22.08.2011
Сообщения
442
Благодарностей
21
Баллы
18
Hello,

I can see that the notifications block has the possibility to be attached to another block and I would like to attach it to an email server, how to do this please?
At the moment when my bot stops and I am away I do not know about it, I would like to receive an email on error.

Thank you.
 

EtaLasquera

Client
Регистрация
02.01.2017
Сообщения
526
Благодарностей
112
Баллы
43
Put a bad end logic.
Connect bad end to a e-mail send script.

c# code to send email:
Код:
//from to cc
var fromEmailString = "[email protected]";
var toEmailString = "[email protected]";
var cc = "[email protected]";

//con string
var login = "smtpuser";
var password = "smtppass";
var server = "mailserver";
int port;
int.TryParse("587", out port); //587 port
bool encryptConnection;
bool.TryParse(project.Variables["crypto"].Value, out encryptConnection);

//message
var messageSubject = "Got error!";
var messageText = "My project X";

//mimimi
var fromAddress = new System.Net.Mail.MailAddress(fromEmailString, fromEmailString);
var toAddress = new System.Net.Mail.MailAddress(toEmailString, toEmailString);
var smtp = new System.Net.Mail.SmtpClient {
                            Host = server,
                            Port = port,
                            EnableSsl = encryptConnection,
                            DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = false,
                            Credentials = new System.Net.NetworkCredential(login, password)
                        };

var message = new System.Net.Mail.MailMessage(fromAddress, toAddress) {
                                        Subject = messageSubject,
                                        Body = messageText,
                                        IsBodyHtml = true,
                                    };

message.CC.Add(cc);

// Attach
var lst = project.Lists["myFiles"];
for (int i = 0; i < lst.Count; i++){
    var anexo1 = lst[i];
    if (!string.IsNullOrEmpty(anexo1))
    {
        var attach = new System.Net.Mail.Attachment(anexo1);
        message.Attachments.Add(attach);
    }
}
smtp.Send(message);
message.Dispose();
 

bambinou

Client
Регистрация
22.08.2011
Сообщения
442
Благодарностей
21
Баллы
18
Brilliant!

Thanks
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)