sending mail from the terminal app

I was wondering if anyone could tell me how to send an email message from the terminal app. I've been trying to figure it out from the man pages and a book I bought, but I can't get anywhere. I don't mean using OSX Mail, but composing an email message and sending to someone else.

I've been trying to make sense of the man pages (mail and sendmail), and tried to, for example send a message to my gmail account, according to what I thought I understood from the man pages:

mail [gmailaccountaddress@gmail.com]
Subject: Test (then I pressed control -D)
EOT
Null message body; hope that's ok

but when I check my gmail account, there's nothing there.
What am I missing?

iMac 24", Mac OS X (10.5.7)

Posted on Jul 24, 2009 4:00 PM

Reply
7 replies

Jul 25, 2009 10:16 AM in response to Knopflerfan

Hi-

You might be having trouble sending because your ISP may be blocking outgoing connections. Or Gmail may be blocking it since it has a null message body. You can try this and see if it helps:

echo `date` | mail -s "Test mail" yourGmailAddress


That would just send the date in your email.

Since you're working in Terminal, you can open up a new window or tab and look in the mail log at what's happening when you try to send mail:

tail /var/log/mail.log


Use "control"-"c" to stop watching the log.

Unless there's a major change in how Postfix is set up in Leopard, you shouldn't need to set up a mail server to send mail using the mail command, it should just work. However, I can't confirm that for sure since the only Mac I have without Postfix configured as a daemon is running Tiger.

charlie

Jul 25, 2009 1:42 PM in response to Knopflerfan

As Charles Minow writes, postfix (=mail server) need not be set up on your Mac (in theory). If you use the "mail" command, postfix is automatically started by the system and will try to send the mail to the destination (by using the default setup).

But there is a (high) possibility that Gmail's server requires authentication (or certification) to connect to it. In this case you need an SMTP client (=a software which directly sends the mail to the Gmail server) which supports authentication. An example of such a client is [smtp-cli|http://www.logix.cz/michal/devel/smtp-cli>. (Mail.app is such a client, but has no command line interface. If I remember correctly Thunderbird has a command line interface).

Jul 25, 2009 7:52 PM in response to Jun T.

Jun T. wrote:
But there is a (high) possibility that Gmail's server requires authentication (or certification) to connect to it.


I wonder if they're simply silently dropping emails in certain cases. I forgot earlier that I have a Gmail account. If I send an email from the command line on my home computer, which is on Comcast, the mail log shows that I successfully connect to Gmail, the message is sent and accepted by Gmail, but the email never arrives in my inbox. I've tried several times with the same result.

However, emails from a web server from work get through to Gmail without a problem. So I'd bet it's a case of them not delivering mail from Comcast IP addresses.

For grins, I also tried sending to my Yahoo email account from my home computer and their server at least refuses the connection and I get an error message stating that it's because it's a residential IP address.

In this case you need an SMTP client (=a software which directly sends the mail to the Gmail server) which supports authentication.


I think this might also be possible with Postfix by editing the configuration files. I know I had to set up authentication to send emails to my work address directly from my home computers, but I haven't been able to get the same thing to work with Gmail yet. If I get a chance, I'll look into it again later tonight.

charlie

Jul 25, 2009 8:46 PM in response to Charles Minow

Charles Minow wrote:
I haven't been able to get the same thing to work with Gmail yet. If I get a chance, I'll look into it again later tonight.


Stupid me. Stupid, stupid me. All the Gmail emails really were getting through, even without any extra special Postfix authentication setup. They were just being marked as spam so I wasn't seeing them in my inbox.

So maybe your mails are going through after all. But definitely look in your mail log and see what's there if you can't find them at Gmail...

charlie

Jul 26, 2009 6:35 AM in response to Knopflerfan

Are you trying to send mail directly from your Mac? If so, give up. It can't be done. Even if you get it configured correctly, there is about a 90% chance the the receiving server will ignore it. Sending e-mail directly from a desktop machine is typical behavior of Windows machines that have been compromised and turned into 'bots to send out spam. A good e-mail server should block connections from such machines.

Only if you are on a private network, can you configure the built-in sendmail system to send e-mail directly.

What you can do is configure sendmail to use your gmail SMTP server to send the mail on your behalf. In this case, sendmail is acting as your e-mail client, as if it were Apple Mail. There must be hundreds of examples on the internet about how to set up this configuration. Here is the top hit from Google.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

sending mail from the terminal app

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