23

I just built a modest home server using CentOS 5.5. I want the server to be able to send emails to my Gmail account or other email accounts for various things like cron jobs. Also it would be nice to be able to send email via PHP applications that I run/develop on the server as well. Or even be able for the server to send emails via the mail command.

I know there are a million Google search results about setting up your Linux server as an email server or configuring sendmail etc. But they don't seem to be what I'm looking for... at least I don't think so. I'm not trying to setup some corporate server that other clients can connect to send out emails or anything complicated like that.

I just want my server to send me emails about stuff. Seems like it should be simple... Can anyone point me in the right direction?

UPDATE

Per a users request below, I tried this command:

/bin/mail -s "My Subject" "myaddress@gmail.com" < /home/john/test

No errors or anything. But the email never showed up in my inbox. Here is my maillog

Oct 27 00:52:19 localhost sendmail[13702]: o9R6qJhU013702: from=root, size=10906, class=0, nrcpts=1, msgid=<201010270652.o9R6qJhU013702@localhost.localdomain>, relay=root@localhost
Oct 27 00:52:19 localhost sendmail[13703]: o9R6qJOd013703: from=<root@localhost.localdomain>, size=11209, class=0, nrcpts=1, msgid=<201010270652.o9R6qJhU013702@localhost.localdomain>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Oct 27 00:52:19 localhost sendmail[13702]: o9R6qJhU013702: to=myaddress@gmail.com, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=40906, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o9R6qJOd013703 Message accepted for delivery)

Any clues?

Jake Wilson
  • 8,494
  • 29
  • 94
  • 121
  • 1
    Have you tried? What sort of problems are you seeing? – Ignacio Vazquez-Abrams Oct 25 '10 at 04:34
  • I'm not sure what I'm looking for. I search Google and see tutorials for setting up a Linux Mail Server. Is that what I want? – Jake Wilson Oct 25 '10 at 04:37
  • Just noticed this was still unanswered. Out of curiosity, have you figured it out? Did you check if the machine was listed on PBL? http://www.spamhaus.org/pbl/ – Belmin Fernandez Nov 30 '10 at 17:20
  • I did not get it to work. I have not gone through the process of installing sendmail yet, because the posters below imply that the it shouldn't be required to simply send a single email. I can't imagine my little home server is listed on a spam list as I've never even sent an email from it before. – Jake Wilson Dec 01 '10 at 02:15
  • I even tried the simple command I listed above sending to a http://10minutemail.com email account with the same result and same log message – Jake Wilson Dec 01 '10 at 02:19

9 Answers9

14

/bin/mail -s "Enter Subject Line here" -a /home/.../whateverFileYouWantAttached "you@YourEmailAddress" < /home/me/textBody.letter

try above command :)

Rajat
  • 3,329
  • 21
  • 29
  • 1
    +1 You don't need a mail server on the system to send mail, just as you don't need a mail server on your desktop to send mail. The mail program is just fine. – dunxd Oct 25 '10 at 07:54
  • 1
    I tried this command and it didn't work. No errors or anything. Just no mail showing up in my gmail inbox. Look above at what my maillog says – Jake Wilson Oct 27 '10 at 06:55
  • So... any reason why this is not working for me? What log should I be looking at to determine why I'm not receiving any mail? – Jake Wilson Dec 01 '10 at 02:22
6

Simple answer:

Set up sendmail. It will depend on your distribution but this isn't difficult at all. If you have any specific questions, ask away.

Complicated answer:

If you're asking this, you probably should not just jump the gun and setup sendmail justtt yet.

You'll need to take a few things into consideration:

  1. Does your ISP allow you to send e-mail? You might be on non-server IP range and therefore, many e-mail providers will block your outright.

  2. What address will you use as your from address? Are you authorized to send from this address (SPF, DomainKeys, etc)? If not, your messages might be detected as spam by e-mail providers---and rightfully so.

  3. Last, but certainly not least: Do you really need to use your own SMTP service? Any reason why using your ISP's is not good enough?

Back in the days, setting up an SMTP server wasn't a big deal. Nowadays, the setup may be easier but setting it up so that it actually gets messages to people's mailboxes, is a challenge.

Belmin Fernandez
  • 10,629
  • 26
  • 84
  • 145
3

I can confirm that none of the above suggestions are working on my CentOS system at home either - not a single one. Which is annoying!

Then I tried the same on a fresh Amazon instance running CentOS 6.4, and even with the default configuration, I can send mail without problems. All I had to do was

yum install mailx

after which sending mail as described above works like a charm. Installing complications like sendmail are NOT necessary for what Jakub is trying to do.

It must be some configuration with my ISP, since I haven't got a configurable firewall at my end here.

Jay Versluis
  • 131
  • 3
2

You need to do the following:

  1. sudo yum install postfix telnet mailx
  2. sudo /etc/init.d/postfix start
  3. sudo vi /etc/postfix/main.cf
  4. Change mydestination = mydomain.com, localhost.mydomain.com, localhost

    to

    mydestination = localhost.mydomain.com, localhost

Test using the following from the command line

  1. mail address@example.com Subject:
  2. Test email from demoslice.com Test
  3. body of the email.
  4. .

No. 4 - there is just a full stop to complete the body of the email. You now should have mail.

The above will get you a working MTA (Mail Transfer Agent). Some resources which will help you with a more advanced setup can be found at slicehost's articles on email setup for CentOS (scroll down to the CentOS and Email section). You should really consider setting the following correctly: hostname, RDNS (Reverse DNS) and SPF (Sender Policy Framework) records with your DNS provider.

Taz
  • 115
  • 5
seanl
  • 470
  • 5
  • 13
1

Have you modified your /etc/mail.rc to set the smtp address?

PiNoYBoY82
  • 111
  • 2
  • 1
    The content of `/etc/mail.rc` is `set ask askcc append dot save crt ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via` What are you suggesting I do? – Jake Wilson Dec 01 '10 at 02:20
0

If there is no smtp server install on localhost, you don't need to install one, just point to the one that you use as an smtp server to send mails.

yum install -y mailx
mail -S smtp={email_host} -s {subject} -r {email_from} {email_to}
Jens Timmerman
  • 866
  • 4
  • 10
0

Try installing postfix & set the mydestination in configuration file even it should work with sendmail.

Caterpillar
  • 1,122
  • 2
  • 22
  • 47
0

Postfix is on the right track, but unless gmail thinks you're at least remotely legit (e.g. You're not a spammer) getting your mail delivered is pretty unlikely.

The process is a bit involved to post here, but the simplest way I have found of achieving this (and having your mail delivered) is to set up postfix as a relay, using your own gmail account as a transport.

The process I use is detailed here:

http://rs20.mine.nu/w/2011/07/gmail-as-relay-host-in-postfix/

No setting up self signed certs are needed (as per sendmail) and in my experience, it just works!

GeoSword
  • 1,647
  • 12
  • 16
0

The easy solution is not sendmail, but sendEmail:

http://caspian.dotconf.net/menu/Software/SendEmail/#download

A perl script that is easily configured to send via whatever SMTP server you can get to -- I use it to send through Gmail accounts all the time, but it also works for ordinary SMTP over TCP on port 25, etc.

I usually wrap the sendEmail perl script with my own shell script for Gmail:

#!/bin/bash

# Send gmail through an account specified in ~/.sendGmailAuthFile (or file identified with -k.)
# The auth file must have values for the -f (from@domain) and -xp (password) options of sendEmail,
# structured as:
#
#    user=me.surnamen@gmail.com
#    pwd=xxxxxxx
#
# We will fill in the rest, and other params are passed through to sendEmail
#
# Example: sendGmail -u "My subject line" -t "test@whatever.com" < message.txt

function sendGmailImmed {
        local authFile="$HOME/.sendGmailAuthFile"
        for arg in "$@"; do
                if [[ "$arg" == "-k" ]]; then
                        shift
                        authFile="$1"
                        shift
                fi
        done
        initAuthFile $authFile
        source $authFile

        sendEmail -f $user -xu $user -xp $pwd -s smtp.gmail.com:587 -o tls=yes "$@"
}

function initAuthFile {
        # If the authfile doesn't exist, we'll create a dummy:
        if [[ ! -f $1 ]]; then
                echo "# sendGmail authentication file: " > $1
                echo "user=my.name@gmail.com" >> $1
                echo "pwd=my-password" >> $1
                echo "A shell auth file has been created as $1"
        fi
}

if [[ -z $sourceMe ]]; then
        sendGmailImmed "$@"
fi
Stabledog
  • 492
  • 4
  • 9