Add Email Account to Postfix – Step-by-Step Guide

postfixUbuntu

I have add a user in linux called "mailer". I'm only using this user to send outgoing mail, not receive. What do I need to do in order use the following SMTP information to send outgoing mail?

$config['host'] = 'localhost';
$config['port'] = '25';
$config['secure'] = '';  //ssl or tls
$config['auth'] = 'true';
$config['username'] = 'mailer';
$config['password'] = '******';

update

Someone please help, how can I setup an account to send mail via SMTP?

update

Should I just be able to use SSH information as the username/password to send mail? The above configuration information is using PHPMailer via SMTP.

update

I ran a test to send email via PHPMailer and the mail logs show…

Aug 31 17:58:55 spireprod postfix/smtpd[14597]: disconnect from unknown[::1]
Aug 31 17:58:55 spireprod postfix/smtp[14601]: DA1491BC1084: to=<email@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.95.27]:25, delay=0.48, delays=0.12/0.01/0.12/0.23, dsn=2.0.0, status=sent (250 2.0.0 OK 1283291935 gy42si22156132ibb.26)
Aug 31 17:58:55 spireprod postfix/qmgr[941]: DA1491BC1084: removed

The problem is that I never received it!

Best Answer

Have you tested whether the account can send mail?

There are a few ways of doing this, but the easiest is to telnet to port 25 (smtp) on your mailserver (try from the local console):

telnet localhost 25
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 myserver.com ESMTP Postfix
EHLO test.com
250-myserver.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from: mailer@myserver.com
250 2.1.0 Ok
rcpt to: test@testaddress.com
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: Test Message
Test
.
250 2.0.0 Ok: queued as 97B7D7640D0

If you see all those 250 OK messages and your message gets through to the test address, then the account is working fine.

If you get an error, then it will indicate where the problem is in the config. If you get an error after the MAIL FROM: command, then the user is not allowed to send mail at all.

If you get an error after the RCPT TO: command, then the user is not allowed to send mail to the test address.

If you get an error after the body of the mail, or the message never arrived, then check your maillog file. It is pretty useful to have another window with a live view of your maillog - tail -f /var/log/maillog will allow you to see what is happening on your mailserver as it happens. Very helpful when tracking things down.

You can also test by switching to the mailer user, and using the mail command to send a test message - view the maillog at the same time to see what happens.