Send email from shell

Status
Not open for further replies.

Scrat

Dabbler
Joined
Jul 25, 2011
Messages
12
Oh Yeah! That's why it doesn't work for you!
Surfing the web I read from many sources that from release 8.0.1b3 there is some problem sending mail with TLS and SSL....

Switch back to 8.0! :D
For me on FN 8.0.1 b4 it's running fine without any problems (see my configuration in my post above). But I must admit, I don't care of the GUI and the testmail of the GUI. For me it's important that I can send mails from a script. :)

Greets, Peter
 

Tekkie

Patron
Joined
May 31, 2011
Messages
353

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Ok, well I tried again like Lucas did, set my port to 587 and the test email from the GUI failed again... BUT, I tried the script again with the port left at 587 and it worked!

Peter, you're right, I'd rather have it work from the shell instead of it just politely telling that the test message worked and never getting anything when there's a problem. Hopefully in the *near* future it will work correctly both ways!

Thanks to both of you for helping to get this working!

Note: This also works (of course without the subject)-

some command, lets say dmesg

dmesg | msmtp -a default myusername@gmail.com
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Lucas, I would recommend you use 'zpool status -v' with your script. It gives you more details about which drive is degraded.
 

Tekkie

Patron
Joined
May 31, 2011
Messages
353
No email field!

Houston we have a problem... no email field on my UI. no_email.jpg
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Tekkie, that's strange, have you tried another browser?

Anyway, you don't need to change email for admin, just root should work fine.

I'm working on an improved script to also check smart status. I'll post it here when I'm done.
 

Tekkie

Patron
Joined
May 31, 2011
Messages
353
I tried, Opera, Chrome and IE9 none show the email box :(

Where do I change the email address for root?
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Left sidebar click Users - View All Users
Look for root on the right side and click "Change E-mail" button
 

Tekkie

Patron
Joined
May 31, 2011
Messages
353
Left sidebar click Users - View All Users
Look for root on the right side and click "Change E-mail" button
Not there either, I can only modify the email of users that I created myself, my installation is a clean 8.0.1-B4 i.e. no upgrade from B3.
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Tekkie, I'm usually the one with the weird problems, are you trying to take away my mojo?? ;)

I just booted my clean beta 4 virtual machine and it was there.
Here's a screen shot just in case you're having tunnel vision, or maybe not...

chg-root.jpg
 

Tekkie

Patron
Joined
May 31, 2011
Messages
353
I will put on my special glasses this weekend and take a look once more...
 

Tekkie

Patron
Joined
May 31, 2011
Messages
353
I will put on my special glasses this weekend and take a look once more...
With ultra special x-ray glasses I did find the option.... :)
 

Tekkie

Patron
Joined
May 31, 2011
Messages
353
Well, my goal is code a simple bash script to check some system parameters and expecially disk state, and send them via mail. That's why I would like to know how to send mail using bash in non interactive mode.
I got my email to work, even with weird error messages in the UI and now I get emails on a daily basis with this info:
Code:
Removing stale files from /var/preserve:

 Cleaning out old system announcements:

 Backup passwd and group files:

 Verifying group file syntax:
 /etc/group is fine

 Disk status:
 Filesystem             Size    Used   Avail Capacity  Mounted on
 /dev/ufs/FreeNASs2a    927M    422M    431M    49%    /
 devfs                  1.0K    1.0K      0B   100%    /dev
 /dev/md0               4.4M    2.4M    1.6M    60%    /etc
 /dev/md1               686K     10K    622K     2%    /mnt
 /dev/md2                75M     18M     51M    26%    /var
 /dev/ufs/FreeNASs4      20M    1.1M     17M     6%    /data
 storage1               301G    304K    301G     0%    /mnt/storage1
 storage1/backup        479G    178G    301G    37%    /mnt/storage1/backup
 storage1/home          309G    7.8G    301G     3%    /mnt/storage1/home
 storage1/pictures      335G     33G    301G    10%    /mnt/storage1/pictures
 storage1/software      348G     47G    301G    13%    /mnt/storage1/software
 backup1                291G    242G     50G    83%    /mnt/backup1

 Last dump(s) done (Dump '>' file systems):

 Checking status of zfs pools:
 all pools are healthy

 Checking status of ATA raid partitions:

 Checking status of gmirror(8) devices:

 Checking status of graid3(8) devices:

 Checking status of gstripe(8) devices:

 Network interface status:
 Name    Mtu Network       Address              Ipkts Ierrs Idrop    Opkts Oerrs  Coll
 em0    7000 <Link#1>      00:1b:21:ad:78:73 14340914     0     0 12176160     0     0
 em0    7000 192.168.1.0   shrek.home        14305402     -     - 19534139     -     -
 lo0   16384 <Link#2>                              20     0     0       20     0     0
 lo0   16384 fe80:2::1     fe80:2::1                0     -     -        0     -     -
 lo0   16384 localhost     ::1                      0     -     -        0     -     -
 lo0   16384 your-net      localhost                0     -     -       20     -     -

 Security check:
    (output mailed separately)

 Checking for denied zone transfers (AXFR and IXFR):

 Scrubbing of zfs pools:
   skipping scrubbing of pool 'backup1':
      last scrubbing is 6 days ago, threshold is set to 30 days
   skipping scrubbing of pool 'storage1':
      last scrubbing is 19 days ago, threshold is set to 30 days

 Checking status of 3ware RAID controllers:
 Alarms (most recent first):
  No new alarms.

 -- End of daily output --

What is it that you want to have in the email that's not in this?
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Yeah, I started getting those now too, but a warning.... If you accidently type your password for your username it gets sent in clear text in that email! Not very good. I might open a ticket for that.

I'm almost ready to post my drive failure detection script with email warning. Of course it'll probably be useless after they fix things they way they should be.... but in the meantime.
 

dumbbell

Dabbler
Joined
Jul 30, 2011
Messages
11
This is the mail config setup by GUI:
Code:
freenas# cat /usr/local/etc/msmtprc
...
port 25
...
tls on
...
tls_starttls off
...

I think there's a bug in /etc/rc.d/ix-msmtp, the script that generates this "msmtprc". It checks if the port number equals 25 and sets tls_starttls to "off" (port == 25) or "on" (port != 25). I think it should be reversed: use STARTTLS when the port is 25 and plain SSL when using 465.

Concerning port 587, I think the behaviour should be the same than 25 ("tls_starttls on") but I'm really not sure because I never encountered this port.

I had a similar problem than yours, Lucas, and setting "tls_starttls" to "off" resolved it.

Edit: The ticket #528 talks about this issue I think.
 

cbray

Explorer
Joined
Jun 16, 2011
Messages
68
Now you've done it!

Now you guys have really done it!!
My working email now does not.
All I did was read your posts.
Haven't even touched my email configurations, or any other configurations at all!
Not even a reboot!
Damn!
What ever you guys are thinking of fixing next, Please Don't!

:p
 

djoole

Contributor
Joined
Oct 3, 2011
Messages
158
Hello,
Now that msmtp has been removed from FreeNAS, could you give me a way to send emails from shell to external accounts (gmail...)?
Thanks in advance :)
 

Milhouse

Guru
Joined
Jun 1, 2011
Messages
564
Hello,
Now that msmtp has been removed from FreeNAS, could you give me a way to send emails from shell to external accounts (gmail...)?
Thanks in advance :)

The following will work in both FreeNAS 0.7 and FreeNAS 8.0.1:

Code:
#!/bin/bash

FROM=me@mydomain.com
TO=me@mydomain.com
SUBJECT="`hostname`: Test Email"
BODY=""

PRINTF=/usr/bin/printf
MSMTP=/usr/local/bin/msmtp
MSMTPCONF=/var/etc/msmtp.conf
#...
BODY="Something"
#...
# Send email in FreeNAS 0.7.x
[   -f $MSMTP ] && $PRINTF "From:$FROM\nTo:$TO\nSubject:$SUBJECT\n\n$BODY" | $MSMTP --file=$MSMTPCONF -t
# Send email in FreeNAS 8.0.1+
[ ! -f $MSMTP ] && $PRINTF "$BODY" | mail -s "$SUBJECT" $TO
 
Status
Not open for further replies.
Top