Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using the ssmtp package to send e-mail via g-mail. Everything is working fine with it - the only strange thing is that if I send mail via the command line, the "to field" is funky.

ssmtp me@domain.com < message.txt

Basically the "to" field will just say "undisclosed recipients"

I read that you can set headers containing a "To:" field, but that seems overly complicated when I've used the mail command on other systems, I it will do this automatically.

Is there an easier way to send mail via the command line with ssmtp - but without having to change the above syntax or specify additional parameters? (possibly a config file to set the "to" address as whatever one was specified.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

This situation comes from a misunderstanding of what ssmtp is doing. There's a very important difference between the message envelope (which mail servers use for routing mail) and the message body (which is displayed in your e-mail client). Both may have To and From, and they may be different from each other. This is okay!

ssmtp merely creates the envelope and facilitates transferring the message to the MTA. It expects the body you pass it to fully formed and contain all body headers. It will not add any for you*, (although it will insert message handling headers, e.g., Received-by, et al.). I'm sure you've also noticed that there is also no Subject: with those messages.

So the answer to your question is that the To: field needs to be included in message.txt.

To make the To: and Subject: fields show up you need to format message.txt like this:

To: cwd@gmail.com
Subject: Message for you

Message text starts here.
blah blah blah.

*That's not exactly true. Since a From: header is the only required header one will be derived from the envelope and inserted if it is missing.

share|improve this answer
    
I guess I didn't realize that I didn't have to use ssmtp and I could use mail to do what I wanted having it actually use ssmtp to send the message. –  cwd Jun 29 '12 at 22:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.