Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Send mail from command line

Hi,
i'd like send e-mail from my mac using localhost like smtp server.
i've tried in two different ways:

1) i started postfix and i sent a mail from my application mail (entourage), it works perfectly but i need to send mails from command line therefore i wrote this command line:


mailx -s "subject" federico@dominio.com
<enter>

doesn't work.... 😟

2) i wrote a shell script

telnet localhost 25 << EOF
HELO apple.com
MAIL FROM: steve.jobs@apple.com
RCPT TO: federico@edominio.com
DATA
.
QUIT

doesn't work.... 😟

any idea?

thanks in advance.

ibook, Mac OS X (10.5.4)

Posted on Aug 13, 2008 11:24 PM

Reply
8 replies

Aug 14, 2008 2:18 PM in response to Federico_82

telnet localhost 25 << EOF
HELO apple.com
MAIL FROM: steve.jobs@apple.com
RCPT TO: federico@edominio.com
DATA
.
QUIT</div>

You're not reading the server's reply to each of your commands. You can't send multiple lines until after the DATA command. If the above works interactively, then try this script (the echo statements are just for a little feedback):
<pre style="padding-left: .75ex; padding-top: .25em; padding-bottom: .25em; margin-top: .5em; margin-bottom: .5em; margin-left: 1ex; max-width: 80ex; overflow: auto; font-size: 10px; font-family: Monaco, 'Courier New', Courier, monospace; color: #444; background: #eee; line-height: normal">#!/bin/sh

function send() {
if [ "$1" ] ; then
printf "%s\r\n" "$1" >&3
echo $1
fi
read status line <&3
echo $status $line
}

if ! exec 3<>/dev/tcp/localhost/25 ; then
echo "Error: Could not connect to localhost on port 25"
exit 1
fi

send "HELO yourdomain.com"
send "MAIL FROM: federico@edominio.com "
send "RCPT TO: federico@edominio.com "
send "DATA"
cat <<EOT >&3
send your
message
Hey there!
.
EOT
send "QUIT"

exec 3<&-
</pre>
--
Cole

Send mail from command line

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.