Problem with email script

I was using this script to send emails:

:local SendFrom "myemail@gmail.com"
:local UserName "myemail@gmail.com"
:local PasswordMail "appPassword"
:local SmtpServer "smtp.gmail.com"
:local SmtpPort 587
:local UseTLS "yes";

/tool e-mail send to=$SendTo server=$SmtpServer port=$SmtpPort start-tls=$UseTLS user=$UserName password=$PasswordMail from=$SendFrom subject=$Subject
body=$TextMail file=$FileName

It was working fine, but now in the logs I see:

Error sending e-mail <netwatch,info [Mikrotik]: event up [ Server ]>: AUTH failed

The password is correct (I have tested it). The version of the routerOS is 7.18.2

What may be wrong?

Are you sure that start-tls parameter for e-mail send command exists on your ROS version? There is tls parameter which accepts yes, no or starttls values - E-mail - RouterOS - MikroTik Documentation

Write in terminal /tool e-mail send and press Tab key on keyboard to see available parameters. If there is tls printed then replace in your command start-tls=$UseTLS with tls=starttls (or use variable).

If this is not tls argument issue, could be character escaping issue in $PasswordMail variable for password value, for eg. if contains $ character. See Scripting - RouterOS - MikroTik Documentation

My first guess, you haven't add app password to use gmail smtp.
You trying to use your regular username and password.
Here a link to YT Video how to setup app password.
https://youtu.be/y5IasMFYdBc

1 Like

well I feel somehow stupid.. The script is ok, I used it the terminal and the email was sent succesfully. The problem was the wrong password in the Tools/Email
Thanks all of you for your help!**
**