I use esmtp
, which is a send-only MTA, for that purpose. It is very simple to set up. It has sendmail-compatible command-line options (some ignored). It's in the repositories.
Here is a simple example:
echo -e "To: Recipient Name <person@example.com>\n\
From: Me Myself and I <me@gmail.com>\n\
Subject: Here is the example I promised\n\n\
$(<somefile)" | /usr/bin/esmtp -t
This sends the contents of the file named "somefile".
There is a very simple configuration file, /etc/esmtprc
, that contains the hostname, username and password for your upstream email provider (I'm assuming yours is gmail).
Instructions for setting it up for Gmail are here.
I have used the following config
ROUTER
send_via_gmail:
driver = manualroute
domains = ! +local_domains
transport = gmail_smtp
route_list = * smtp.gmail.com
TRANSPORT
gmail_smtp:
driver = smtp
port = 587
hosts_require_auth = $host_address
hosts_require_tls = $host_address
AUTHENTICATOR
gmail_login:
driver = plaintext
public_name = LOGIN
client_send = : alex.hha@gmail.com : 7654321
Some simple test
# swaks -s 127.0.0.1 --to user@example.net --from alex.hha@gmail.com
=== Trying 127.0.0.1:25...
=== Connected to 127.0.0.1.
<- 220 mail.example.net, [127.0.0.1]
-> EHLO mail.example.net
<- 250-mail.example.net Hello localhost [127.0.0.1]
<- 250-SIZE 52428800
<- 250-PIPELINING
<- 250-STARTTLS
<- 250 HELP
-> MAIL FROM:<alex.hha@gmail.com>
<- 250 OK
-> RCPT TO:<user@example.net>
<- 250 Accepted
-> DATA
<- 354 Enter message, ending with "." on a line by itself
-> Date: Wed, 05 Mar 2014 10:22:55 -0500
-> To: user@example.net
-> From: alex.hha@gmail.com
-> Subject: test Wed, 05 Mar 2014 10:22:55 -0500
-> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
->
-> This is a test mailing
->
-> .
<- 250 OK id=1WLDep-0004ED-Kb
-> QUIT
<- 221 mail.example.net closing connection
=== Connection closed with remote host.
Check maillog file
# cat /var/log/exim/main.log | grep 1WLDep-0004ED-Kb
2014-03-05 10:22:55 1WLDep-0004ED-Kb <= alex.hha@gmail.com H=localhost (mail.example.net) [127.0.0.1] P=esmtp S=479
2014-03-05 10:22:55 1WLDep-0004ED-Kb gmail-smtp-msa.l.google.com [2a00:1450:4001:c02::6d] Network is unreachable
2014-03-05 10:23:00 1WLDep-0004ED-Kb => user@example.net R=send_via_gmail T=gmail_smtp H=gmail-smtp-msa.l.google.com [173.194.70.108] X=UNKNOWN:ECDHE-RSA-AES128-GCM-SHA256:128
2014-03-05 10:23:00 1WLDep-0004ED-Kb Completed
You can run exim in debug mode
# echo -e "helo localhost\nmail from:<me@domain.com>\nrcpt to:<someone@gmail.com>\nDATA\nHello world\n.\nquit" | exim -bhc 127.0.0.1 -d+all
After that you get a lot of data. Add the output to the question
Best Answer
What MTA are you using locally?
mail
just gives you the ability to form a mail message, but you still need and MTA to do the actual delivery? By default, most distributions come with sendmail. You'll likely need to install another MTA or configure the current one to support outside delivery.