# [SOLVED] outgoing mail not working

## Joseph_sys

On one of my remote boxes outgoing mail is not working.

Local mail is being delivered OK but trying to send the mail out is not working.

I'm not sure where to start.

my main.cf

```
queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = //usr/lib64/postfix

data_directory = /var/lib/postfix

mail_owner = postfix

mydestination = $myhostname, localhost.localdomain

unknown_local_recipient_reject_code = 550

 

  

debug_peer_level = 2

debugger_command =

    PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin

    ddd $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail

newaliases_path = /usr/bin/newaliases

mailq_path = /usr/bin/mailq

setgid_group = postdrop

html_directory = /usr/share/doc/postfix-2.8.7/html

manpage_directory = /usr/share/man

sample_directory = /etc/postfix

readme_directory = /usr/share/doc/postfix-2.8.7/readme

home_mailbox = .maildir/

default_destination_concurrency_limit = 2

alias_database = hash:/etc/mail/aliases

local_destination_concurrency_limit = 2

alias_maps = hash:/etc/mail/aliases
```

Last edited by Joseph_sys on Sun Mar 18, 2012 1:37 am; edited 1 time in total

----------

## cach0rr0

start with the logs. 

protip: if you emerge syslog-ng with USE="hardened" you get a separate mail.log, makes things much easier to parse (though you can always make that change to syslog's conf yourself manually, this way is quick and easy)

anyway, yeah, start with logs - and are things simply queuing up, or are you getting messages rejected, or which? 

If they're queuing up:

-try to telnet to one of the remote MTA's on port 25, see if you can successfully connect

-try manually doing an MX lookup for a remote domain, make sure it's successful

if this is postfix, do a "postfix reload" followed by a "postfix flush", and check the logs for errors. 

Nothing wrong with your main.cf that i can see

----------

## Joseph_sys

log via:

tail -f /var/log/messages

```

Mar 17 12:07:45 localhost sshd[3817]: SSH: Server;Ltype: Version;Remote: 192.168.141.8-58330;Protocol: 2.0;Client: OpenSSH_5.8p1-hpn13v10lpk

Mar 17 12:07:46 localhost sshd[3817]: Accepted publickey for thelma from 192.168.141.8 port 58330 ssh2

Mar 17 12:07:46 localhost sshd[3817]: pam_unix(sshd:session): session opened for user thelma by (uid=0)

Mar 17 12:07:57 localhost postfix/pickup[3666]: 43BEE9BE40: uid=1000 from=<thelma>

Mar 17 12:07:57 localhost postfix/cleanup[3837]: 43BEE9BE40: message-id=<1000_3833_1332007677_1@clinic-atom>

Mar 17 12:07:57 localhost postfix/qmgr[3441]: 43BEE9BE40: from=<thelma@clinic-atom.localdomain>, size=405, nrcpt=1 (queue active)

Mar 17 12:07:57 localhost postfix/cleanup[3837]: 4EF5E9BE3F: message-id=<1000_3833_1332007677_1@clinic-atom>

Mar 17 12:07:57 localhost postfix/qmgr[3441]: 4EF5E9BE3F: from=<thelma@clinic-atom.localdomain>, size=552, nrcpt=1 (queue active)

Mar 17 12:07:57 localhost postfix/local[3839]: 43BEE9BE40: to=<root@clinic-atom.localdomain>, orig_to=<root>, relay=local, delay=0.08, delays=0.05/0.01/0/0.01, dsn=2.0.0, status=sent (forwarded as 4EF5E9BE3F)

Mar 17 12:07:57 localhost postfix/qmgr[3441]: 43BEE9BE40: removed

Mar 17 12:07:59 localhost postfix/smtp[3840]: 4EF5E9BE3F: to=<info@sys-concept.com>, orig_to=<root>, relay=mx1c11.megamailservers.com[69.49.101.234]:25, delay=2.5, delays=0.01/0.01/2.3/0.21, dsn=5.7.1, status=bounced (host mx1c11.megamailservers.com[69.49.101.234] said: 550 5.7.1 <info@sys-concept.com>... H:DBL [68.151.252.245] Connections originating from dynamically assigned IP addresses are not allowed. Please use your ISP's relay servers. (in reply to RCPT TO command))

Mar 17 12:07:59 localhost postfix/cleanup[3837]: E0AD89BE43: message-id=<20120317180759.E0AD89BE43@clinic-atom.localdomain>

Mar 17 12:07:59 localhost postfix/qmgr[3441]: E0AD89BE43: from=<>, size=2897, nrcpt=1 (queue active)

Mar 17 12:07:59 localhost postfix/bounce[3841]: 4EF5E9BE3F: sender non-delivery notification: E0AD89BE43

Mar 17 12:07:59 localhost postfix/qmgr[3441]: 4EF5E9BE3F: removed

Mar 17 12:07:59 localhost postfix/local[3839]: E0AD89BE43: to=<thelma@clinic-atom.localdomain>, relay=local, delay=0.03, delays=0.01/0/0/0.01, dsn=2.0.0, status=sent (delivered to maildir)

Mar 17 12:07:59 localhost postfix/qmgr[3441]: E0AD89BE43: removed
```

Here is my main.cf setting:

sed -e 's/#.*//' -e '/^$/ d' main.cf

```
queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = //usr/lib64/postfix

data_directory = /var/lib/postfix

mail_owner = postfix

mydestination = $myhostname, localhost.localdomain

unknown_local_recipient_reject_code = 550

 relayhost = shawmail.ed.shawcable.net

debug_peer_level = 2

debugger_command =

         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin

         ddd $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail

newaliases_path = /usr/bin/newaliases

mailq_path = /usr/bin/mailq

setgid_group = postdrop

html_directory = /usr/share/doc/postfix-2.8.7/html

manpage_directory = /usr/share/man

sample_directory = /etc/postfix

readme_directory = /usr/share/doc/postfix-2.8.7/readme

home_mailbox = .maildir/

default_destination_concurrency_limit = 2

alias_database = hash:/etc/mail/aliases

local_destination_concurrency_limit = 2

alias_maps = hash:/etc/mail/aliases
```

I'm trying to mail using standard "mailto" command

I'm only using postfix and it seems to me the mail is trying to go directly to:

mx1c11.megamailservers.com

I'm not sure where is it getting it from.

----------

## cach0rr0

emerge bind-tools, and do a host -t MX gmail.com see what it comes back with 

NB: i dont know if having a space prepended to relayhosts will be problematic or not. 

 *Quote:*   

> 
> 
> to=<info@sys-concept.com>, orig_to=<root>, 
> 
> 

 

Why are messages to root being redirected to 'info@sys-concept.com' ?

That MX is correct for that domain. The real question is, why the rewrite? Is that in your aliases.db ?

```

meat@hplaptop ~ $ host -t MX sys-concept.com

sys-concept.com mail is handled by 11 mx2c11.megamailservers.com.

sys-concept.com mail is handled by 10 mx1c11.megamailservers.com.

sys-concept.com mail is handled by 12 mx3c11.megamailservers.com.

```

NB: the postfix 'smtpd' process is the server component (handles inbound smtp) while the 'smtp' process is the client component (handles sending outbound mail). So you can cut out some of the clutter if you only care about troubleshooting outbound mail using 

```

tail -n1 -f /var/log/messages | grep 'postfix/smtp\['

```

(note the [ else you end up with smtpd lines)

At least in this example the reason for the bounce message is very clear. A message came in for root. It was rewritten for some inexplicable reason to be this external recipient. An MX lookup for this external recipient was done, postfix attempted to connect to said MX, and the remote MTA rejected it. 

Suspecting something a bit funky in /etc/mail/aliases 

I also don't see where youve set $myhostname - granted the default may be ok, but i dont trust it, and you do reference it within $mydestination

----------

## Joseph_sys

Thanks for your help.

host -t MX gmail.com gives me:

```
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.

gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.

gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.

gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.

gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
```

I have two remote boxes running Gentoo and so in /etc/mail/aliases I have:

root:		   info@sys-concept.com

These remote boxes are not setup for any incoming email (except google.mail); during compiling I'm receiving email from from the remote boxes, IP changes etc, to my email address info@sys-concept.com

host -t MX sys-concept.com (my domain) is being handled by shaw mail server.

The boxes in the remote location has an account with Shaw as well but no domain so I was told to use:

shawmail.ed.shawcable.net

that is why I put in main.cf

relayhost = shawmail.ed.shawcable.net

but for some reason or another the mail is being rejected.  

```
tail -n1 -f /var/log/messages | grep 'postfix/smtp'
```

gives me:

```
localhost postfix/smtp[14549]: EDADE81C22: to=<info@sys-concept.com>, orig_to=<root@clinic-amd.localdomain>, relay=mx1c11.megamailservers.com[69.49.101.234]:25, delay=2.4, delays=0.03/0/2.2/0.14, dsn=5.7.1, status=bounced (host mx1c11.megamailservers.com[69.49.101.234] said: 550 5.7.1 <info@sys-concept.com>... H:DBL [68.151.252.245] Connections originating from dynamically assigned IP addresses are not allowed. Please use your ISP's relay servers. (in reply to RCPT TO command))
```

does 

mx1c11.megamailservers.com = shawmail.ed.shawcable.net ?

if so why mail is getting rejected.

I tried commenting out the line:

mydestination =  $myhostname, localhost.localdomain

but it makes no difference, still mail is being rejected.

----------

## Joseph_sys

I recompile postfix and it is giving me an error at the end: 

```
* for incompatibilities and other major changes between releases.

sendmail: fatal: file /etc/postfix/main.cf: parameter mail_owner: unknown user name value: postfix mydestination =  clinic-amd.localdomain, localhost.localdomain

!!! /usr/sbin/sendmail returned with a non-zero exit code. This generally indicates an error.

>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.
```

I can not find any: clinic-amd in main.cf 

so why am I getting this error?

----------

## Joseph_sys

SOLVED!

I had to reinstall postfix (unmerge and remove mail.cf)

Something was not as it suppose to, despite the fact that mail.cf on both systems was almost identical.  On my other system postfix wouldn't work I had to unmerge it and delete main.cf

----------

## cach0rr0

 *Joseph_sys wrote:*   

> 
> 
> The boxes in the remote location has an account with Shaw as well but no domain so I was told to use:
> 
> shawmail.ed.shawcable.net
> ...

 

shawmail.ed.shawcable.net !=  megamailservers

your relayhost was being ignored, and a DNS lookup was being performed. 

Commenting out mydestination was not what I was suggesting. I was suggesting you remove the space before the relayhost setting

You had:

```

 relayhost=shawmail.ed.shawcable.net

```

I cant help but think the spurious whitespace was causing a problem that prompted relayhost not to be processed, so my suggestion was to change to

```

relayhost=shawmail.ed.shawcable.net

```

TLDR: your fundamental problem is that mail destined for sys-concept.com is not going through your relayhost, but rather the MX record for sys-concept.com is being looked up by postfix/smtp, and that MX record points to that mail server you see in the logs that keeps rejecting your mail. 

relayhost is supposed to override all DNS MX lookups on mail delivery, and just blindly send to the relayhost specified. Ergo, it would say to me that postfix is/was seeing your relayhost as unset/undefined. If you do a DNS lookup for sys-concept.com, you get:

```

renee ~ # host -t MX sys-concept.com

sys-concept.com mail is handled by 10 mx1c11.megamailservers.com.

sys-concept.com mail is handled by 12 mx3c11.megamailservers.com.

sys-concept.com mail is handled by 11 mx2c11.megamailservers.com.

```

The fact that it's going there says relayhost is not being processed. If you were still using your old main.cf, we could test that theory via:

```

postconf -n |grep relayhost

```

If that yielded no results, it would mean indeed postfix did not see your override of 'relayhost', and that relayhost was undefined, ergo not being used. 

postconf -n shows any of postfix's current settings that are not default (i.e. settings that youve overridden by making a configuration file, main.cf - that's actually one point i dont think people make terribly clear in doc, postfix will run without a main.cf, using its built-in default settings for each of the different variables; what you're doing when you make a main.cf is creating overrides for each of those variables)

see `man postconf` for full details

The absence of 'relayhost' in `postconf -n` output tells you that postfix is using the default value for relayhost, which is 'undefined' e.g. dont use a relayhost

----------

## Joseph_sys

 *cach0rr0 wrote:*   

> [snip]
> 
> your relayhost was being ignored, and a DNS lookup was being performed. 
> 
> Commenting out mydestination was not what I was suggesting. I was suggesting you remove the space before the relayhost setting
> ...

 

Thank you for your explanation again.  Yes, now I understand the process.

Regarding the extra spacing in:

relayhost=shawmail.ed.shawcable.net

vs. 

relayhost = shawmail.ed.shawcable.net

I'm not sure it was causing a problem.  It is hard to tell now as I rebuild both "postfix" on both boxes and deleted the old main.cf :-/.

Thanks for the hint: "postconf -n" If I only new that command earlier it would be easer to lookup where the problem was.

It is very practical command I'll put it in my cheat sheet  :Smile: 

As a note, the new main.cf still has spaces between " = "

relayhost = shawmail.ed.shawcable.net

and it is working OK.  So it is hard to tell if this was causing the problem.

----------

## cach0rr0

regarding the extra space:

the space im referring to is the very first character on the line

i dont know for certain it was causing a problem, but what i was referring to was

<space>relayhost=blah

which is what your sed'd main.cf output up above shows

whereas using:

relayhost<space>=<space>blah

or

relayhost=blah

should not make a difference. As in, I wonder if having the space as the first character on the 'relayhost' line wasnt causing the problem. Do i know that for a fact or have any rational reasoning for thinking that? Nope, just a gut instinct/baseless assumption

Either way, hopefully these are at the very least pointers for the future thatll be helpful  :Smile: 

----------

## Joseph_sys

 *cach0rr0 wrote:*   

> [snip]
> 
> i dont know for certain it was causing a problem, but what i was referring to was
> 
> <space>relayhost=blah
> ...

 

I just tested it again and you are absolutely correct.

The leading "space" before  "relayhost..."  is causing the problem.  If I remove the space the mail is going out to correct relay address.

Huh, always learn something new.

That was a valuable lesson  :Smile:  thank you.

----------

