No you do not require a mail server to send mail. I'm most familiar with Sendmail and there are 3 classifications of functionality that fulfill email as a service. MDA (Mail Delivery Agents) is 1, and MTA (Mail Transfer Agents) is 2, and 3 is MUA (Mail User Agents).
The terminology get's confusing but you do not require an MTA to be running all the time. The MTA will be called each time the MUA (mail
) wants to "send" mail.
When you run mail
and you specify an address to send mail to, sam@example.com
. The mail client will summon the MTA (/usr/bin/sendmail
) which will then query DNS for that host/domain (example.com), and find out what value is designated for its MX record. MX stands for Mail Exchanger.
Example
You can use the dig
command to see this:
$ dig gnu.org mx
; <<>> DiG 9.7.4-P1-RedHat-9.7.4-2.P1.fc14 <<>> gnu.org mx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21053
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 2
;; QUESTION SECTION:
;gnu.org. IN MX
;; ANSWER SECTION:
gnu.org. 299 IN MX 10 eggs.gnu.org.
;; ADDITIONAL SECTION:
eggs.gnu.org. 299 IN A 208.118.235.92
eggs.gnu.org. 299 IN AAAA 2001:4830:134:3::10
;; Query time: 218 msec
;; SERVER: 192.168.1.8#53(192.168.1.8)
;; WHEN: Thu Oct 3 17:27:22 2013
;; MSG SIZE rcvd: 90
So the client will attempt to connect to eggs.gnu.org on port 25 to deliver this email.
DNS server?
@puk asked the following follow-up question:
Is this DNS on my local machine?
To which I replied:
@puk - it can be in the same manner that the mail server can be, but typically it's not. Look in your /etc/resolv.conf
file and also when you run the dig
command you'll notice the SERVER: ...
line at the bottom. That's the DNS server servicing your request.
Example
My /etc/resolv.conf
file contains the following:
nameserver 192.168.1.8
And queries such as this one, using dig
:
$ dig gnu.org mx
Result in this at the bottom:
;; Query time: 259 msec
;; SERVER: 192.168.1.8#53(192.168.1.8)
;; WHEN: Thu Oct 3 17:46:13 2013
;; MSG SIZE rcvd: 90
And for the astute reader, one my ask, how is this configured? The answer is the /etc/nsswitch.conf
file. Specifically this line:
hosts: files mdns4_minimal [NOTFOUND=return] dns
That says, use files first (/etc/hosts
), followed by mdns4_minimal
. That's a multicast DNS. It's basically a cache of previous look ups. Lastly it uses dns
which is the IP address of the nameserver
designated in the /etc/resolv.conf
file.
set "/home/user/path to files/"*.xls
for f do [ "$f" -nt "$two_day_old_file" ] && set "$@" "$f" ; shift ; done
touch "$two_day_old_file"
echo $MBODY | mutt -s "Data files for $TODAY" -a "$@" -- $EMAILS
To mail them one at a time change the echo
line to:
for mailf do echo "$MBODY" |
mutt -s "Data files for $TODAY" -a "$mailf" -- $EMAILS
done
Would probably work, but your real problem lies here:
...
set IFS=...
...
This doesn't affect the value of the internal field separator at all, but rather it assigns the value IFS=...
to the first positional parameter, or $1
. $IFS
remains valued at whatever it was before you set
$1
. You just need to do:
IFS='
'
Or...
IFS=${IFS# }
...if $IFS
is set to the default value, which it must be if this is an executable script and you have not altered $IFS
anywhere else in the script.
Best Answer
The
mail
program expects the user to type the message on its standard input (terminated by EOF (Ctrl-D)). You are not redirecting stdin, the program is waiting for input. You can either redirect from/dev/null
(for an empty message), from a canned file, or from a pipe, for example:or
Both of these should clear up problem.