Backup over e-mail help?

Hi

add name=backup policy=ftp,reboot,read,write,policy,test,winbox,password,sniff source=":log info \"backup beginning now\"\r\
    \n:global backupfile ([/system identity get name] . \"-\" . [/system clock get time])\r\
    \n/system backup save name=\$backupfile\r\
    \n:log info \"backup pausing for 15s\"\r\
    \n:delay 15s\r\
    \n:log info \"backup being emailed\"\r\
    \n/tool e-mail send tls=yes to=\"xxx@gmail.com\" subject=([/system identity get name] . \\\r\
    \n\" Backup\") from=ROUTER@mt.com file=\$backupfile server=xx.xx.xx.xx\r\
    \n:log info \"backup finished\""

xx is router IP.
When I run the script it create a backup file but it doesn’t send e-mail. It said Error sending mail: error connecting to server. What am I doing wrong and what am I missing? ROS is 4.17. :confused:
Can anyone help me?

:log info "backup beginning now"
:local Date ([:pick [/system clock get date] 7 11] . "-" \
     . [:pick [/system clock get date] 0 3] . "-" \
     . [:pick [/system clock get date] 4 6])
:global backupfile ([/system identity get name] . "-" . $Date )
/system backup save name=$backupfile
:log info "backup pausing for 15s"
:delay 15s
:log info "backup being emailed"
/tool e-mail send to="xxx@gmail.com" subject=([/system identity get name] . \
" Backup") from=xxx@gmail.com file=$backupfile server=[:resolve smtp.gmail.com]
:log info "backup finished"

587 port is set in tools email, username and password is also set.
Now, it said Error sending mail: error handling file. What am I doing wrong and what am I missing? ROS is 4.17. :confused:
Blank mail sent without trouble and it’s working on ROS 3.30 perfectly :astonished:

smtp.gmail.com: don’t forget to enable TLS (tls=yes)?
I wish this setting could be set in server section, and not each time an email has to be sent.

Yes… I tried with tls= yes and I also get all the same. And tls should be on by default as I remember correct?
This looks like some kind of bug in ROS 4 since it works in 3.

Does anyone knows how to make this work?

This works for me (rosv.5.1):

/system scheduler
add disabled=no interval=1w name=e-mail_backup on-event=send_backup_mail policy=\
    reboot,read,write,policy,test,password,sniff,sensitive start-date=jan/01/2011
/
/system script
add name=send_backup_mail policy=ftp,read,write,policy,test,winbox,sensitive,api source="/system backup save name=email_backup\r\
    \n/tool e-mail send file=email_backup.backup to=\"yourname@yourdomain.xx\" body=\"See attached file\" \\\r\
    \n   subject=\"\$[/system identity get name] \$[/system clock get time] \$[/system clock get date] Backup\""

/tool e-mail
set address="smtpmailserverIP" from="yourrouter"@"yourdomain.xx" password="yoursmtpserverpassword" port=25 username="yoursmtpserverloginname"

data inbetween " " you have to fill in your own details.

No luck :frowning:
When i tried to input script it said

input does not match any value of policy

api part is not available in 4.17. Without it, it’s ok but it have error when run, invalid FROM address.

hmmm… guess I’ll have to upgrade on ROS 5.1 or to downgrade to 3.30 if I want to make this work that way…
So, is it possible to make this script or my to work on 4.17?

All I noticed over time is that many times when MT comes with ROS upgrades the scrip language is changed here or there a little bit as well. Very irritating. You never know what works and each time you have to find out yourself how it is done this time… :frowning:

Put the script line by line in terminal screen and you’ll see where the errors come up. Then start to try finding the proper format for making the script…
Start by using scripts, scheduler etc. with all policies enabled. After the script than works you can narrow the policies it has to work for by disabling the ones that should not be enabled.

put all parameters in quotes. The backup file name is probably causing issues on the send email line, quote them and see if that helps. also, the policy refers to the permissions on the script, check all those boxes to allow it access on the scheduler/script.

why would i get error like this
error.png

the smtp server is not ready to recieve your mail. Check your authentication. I had same error and after correcting my username it worked…

Good thinking… it worked. I placed [ ] on $backupfile and it worked. So, this one is working on gmail with port 587. Make note that simply get date WON’T WORK because of format printout (year/month/day) format. It needs to be (year-month-day) and you can play with a script and change sequence :sunglasses:

:log info “backup beginning now”
:local Date ([:pick [/system clock get date] 7 11] . “-”
. [:pick [/system clock get date] 0 3] . “-”
. [:pick [/system clock get date] 4 6])
:global backupfile ([/system identity get name] . “-” . $Date )
/system backup save name=$backupfile
:log info “backup pausing for 15s”
:delay 15s
:log info “backup being emailed”
/tool e-mail send to=“> xxx@gmail.com> " subject=([/system identity get name] .
" Backup”) from=> xxx@gmail.com > file=[$backupfile] server=[:resolve smtp.gmail.com] tls= yes
:log info “backup finished”

It works now on ROS 4 :sunglasses:

this is my script all works but want to add a delay between emails sent
so in other words for foreach i i need
send email delay 00:00:10 then next value of i
then send again etc
as it thells me to many smtp connections to that server

/tool user-manager user
:foreach i in=[ /tool user-manager user find customer=bren ] do={
:set disabled [get $i disabled]
:if ([$disabled] = false) do={
:set date [/system clock get date]
:set usrname [get $i name]
:set uptime [get $i uptime-used]
:set clientname [get $i first-name]
:set clientsurname [get $i last-name]
:set comment [get $i comment]
:set cap [:pick $comment 5 9]
:set warning [:pick $comment 9 11]
:if ([get $i download-used] > 0) do={ :set bytesin [get $i download-used] } else={ :set bytesin 0 }
:if ([get $i upload-used] > 0) do={ :set bytesout [get $i upload-used] } else={ :set bytesout 0 }
:set bytestotal ($bytesin + $bytesout)
:set gigstotal ($bytestotal / 1000000)
:set email [get $i email]
:if ([$total] = 0) do={ :set doespay “This is a Complimentary Account”} else={ :set doespay “-” }
/tool e-mail send to=$email password=x.x.x.x server=“x.x.x.x” from=NoReply@admin.co.za user=admin@admin.co.za subject=“[Usage info for user $usrname]” body="[info sent to $email

:delay 10s

Well… try to add this at the end of the script.