简体   繁体   中英

Bash script Ubuntu mailx

I want to send an email from a bash script when my script creates a new file.

This is the code I have written so far:

SUBJECT="MyNotifier"
TO="nobody@gmail.com"

echo "mail body. Something happened here.... hope you get this!" | mailx -s "$SUBJECT" "$TO" 

The point is I don't get any error messsages neither mails.

I have only downloaded and instaled mailx (with the sudo apt-get command - excuse me I am noob)

I haven't configured it at all.

What am I doing wrong? Thanks in advance

Quite likely your sendmail/exim server isn't configured -- and as such the emails are being sent to the MTA (mail transport agent) but are left in the queue. If you issues a mailq command you should see the list of mails currently waiting to be sent -- if there are mails in the queue then you need to configure your MTA, if there are no mails in the mailq then your emails were sent but were probably discarded by the receiver (there are many reasons why this would happen -- and you can find lots of resources on google on it, however a very common one is if your sender domain doesn't map back to the ip you sent an email from).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM