Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
76 views
76 views

For testing a new mail server (Postfix) I need to send an email locally, preferably from the commandline. I know I can use netcat or telnet to talk to the SMTP service directly

me@server:~ $ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 foo.example.com ESMTP Postfix
helo example.org
250 foo.example.com
mail from:<me@example.org>
250 2.1.0 Ok
rcpt to:<postmaster@foo.example.com>
250 2.1.5 Ok
data
354 End data with .
Subject: test

test
.
250 2.0.0 Ok: queued as A103C452
quit
221 2.0.0 Bye
Connection closed by foreign host.

but isn't there a more convenient way?

in General by (275) 7

Your answer

Preview

Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
By submitting this post you agree to our Terms & Conditions.
To avoid this verification in future, please log in or register.

1 Answer

0 votes
 

There are several ways, actually.

The simplest approach is most likely the sendmail command that ships with Postfix, since that does not require additional software:

from='me@example.org'
to='postmaster@foo.example.com'
subj='Foo'
msg='Your message.'

echo -e "Subject: ${subj}\n\n${msg}" | sendmail -f "$from" "$to"

Another option would be the mailx commandline utility. However, you probably need to install that first (for Debian-based systems it's in the package bsd-mailx):

from='me@example.org'
to='postmaster@foo.example.com'
subj='Foo'
msg='Your message.'

echo "$msg" | mailx -r "$from" -c '' -s "$subj" "$to"

Or you could install something like Mutt, which provides you with an ncurses-based interface. The program needs some configuration, though. Create a file .muttrc with the following content in your userhome:

# ~/.muttrc
set mbox_type=maildir
set spoolfile="/var/mail/USERNAME"
set folder="~/Mail/"

Replace USERNAME with your actual username on the system.

You can instruct the client to use a specific from address by adding this line:

set from=me@example.org

and/or make headers (including the From: header) editable by adding

set edit_hdrs=yes
by (275) 7
edited by
...