Community discussions

MikroTik App
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Backup over e-mail help?

Wed Apr 13, 2011 10:07 pm

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. :?
Can anyone help me?
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Re: Backup over e-mail help?

Thu Apr 14, 2011 2:15 am

: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. :?
Blank mail sent without trouble and it's working on ROS 3.30 perfectly :o
 
User avatar
elgo
Member Candidate
Member Candidate
Posts: 151
Joined: Sat Apr 02, 2011 2:34 am
Location: France

Re: Backup over e-mail help?

Thu Apr 14, 2011 11:36 am

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.
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Re: Backup over e-mail help?

Thu Apr 14, 2011 12:41 pm

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.
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Re: Backup over e-mail help?

Thu Apr 14, 2011 11:52 pm

Does anyone knows how to make this work?
 
WirelessRudy
Forum Guru
Forum Guru
Posts: 3119
Joined: Tue Aug 08, 2006 5:54 pm
Location: Spain

Re: Backup over e-mail help?

Fri Apr 15, 2011 3:17 am

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.
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Re: Backup over e-mail help?

Fri Apr 15, 2011 3:26 pm

No luck :(
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?
 
WirelessRudy
Forum Guru
Forum Guru
Posts: 3119
Joined: Tue Aug 08, 2006 5:54 pm
Location: Spain

Re: Backup over e-mail help?

Fri Apr 15, 2011 5:56 pm

No luck :(
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..... :(

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.
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: Backup over e-mail help?

Fri Apr 15, 2011 7:37 pm

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.
 
xezen
Long time Member
Long time Member
Posts: 628
Joined: Fri May 30, 2008 10:23 am
Location: South Africa

Re: Backup over e-mail help?

Fri Apr 15, 2011 11:16 pm

why would i get error like this
You do not have the required permissions to view the files attached to this post.
 
WirelessRudy
Forum Guru
Forum Guru
Posts: 3119
Joined: Tue Aug 08, 2006 5:54 pm
Location: Spain

Re: Backup over e-mail help?

Sat Apr 16, 2011 12:41 am

why would i get error like this
the smtp server is not ready to recieve your mail. Check your authentication. I had same error and after correcting my username it worked...
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Re: Backup over e-mail help?

Sun Apr 17, 2011 4:21 pm

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.

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 8)
: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 8)
 
xezen
Long time Member
Long time Member
Posts: 628
Joined: Fri May 30, 2008 10:23 am
Location: South Africa

Re: Backup over e-mail help?

Sun Apr 17, 2011 9:17 pm

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
 
User avatar
mves
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 91
Joined: Tue Jan 11, 2011 8:15 pm
Location: Serbia

Re: Backup over e-mail help?

Fri Apr 29, 2011 5:06 pm

:delay 10s
Well... try to add this at the end of the script.

Who is online

Users browsing this forum: Amazon [Bot], britgent, Cloudtechiq [Bot], rextended, rjuho, VinceKalloe and 91 guests