Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I can't send mail to external email addresses such as gmail.

When I try to send a mail with telnet I get the following error:

Trying 130.xx.xx.128...
Connected to mydomain.com.
Escape character is '^]'.
220 server2.mydomain.com ESMTP Postfix
mail from: info@mydomain.com
250 2.1.0 Ok
rcpt to: mymail@gmail.com
554 5.7.1 <mymail@gmail.com>: Relay access denied

This is my main.cf file:

queue_directory = /var/spool/postfix

command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
inet_interfaces = all 
inet_protocols = all 
mydestination = server2.myserver.com, localhost, localhost.localdomain
unknown_local_recipient_reject_code = 550 
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
debug_peer_level = 2 
debugger_command =
         ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.6.6/samples
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
virtual_alias_domains = $virtual_alias_maps  
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf
virtual_mailbox_base = /var/vmail
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
smtpd_sasl_auth_enable = yes 
broken_sasl_auth_clients = yes 
smtpd_sasl_authenticated_header = yes 

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:/etc/postfix/mysql-virtual_recipient.cf, reject_unauth_destination
smtpd_use_tls = yes
smtpd_tls_security_level = may
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.key
transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf
relay_domains = mysql:/etc/postfix/mysql-virtual_relaydomains.cf
relay_recipient_maps = mysql:/etc/postfix/mysql-virtual_relayrecipientmaps.cf
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps
smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf
smtpd_client_restrictions = check_client_access mysql:/etc/postfix/mysql-virtual_client.cf
maildrop_destination_concurrency_limit = 1
maildrop_destination_recipient_limit = 1
virtual_transport = maildrop
header_checks = regexp:/etc/postfix/header_checks
mime_header_checks = regexp:/etc/postfix/mime_header_checks
nested_header_checks = regexp:/etc/postfix/nested_header_checks
body_checks = regexp:/etc/postfix/body_checks
myhostname = server2.myserver.com
mynetworks = [::1]/128
content_filter = amavis:[]:10024
receive_override_options = no_address_mappings

What should I do?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

The key to understanding your problem is the following two lines.

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:/etc/postfix/mysql-virtual_recipient.cf, reject_unauth_destination
mynetworks = [::1]/128

mynetworks lists only localhost, and there is nothing in your connection transcript to indicate that you are connecting to localhost (in fact, there's plenty to indicate that you are not). And you are not authenticating through SASL.

So you are almost certainly hitting the reject_unauth_destination at the end, meaning that the mail transaction is denied.

Either connect to your mail server over the loopback interface, or augment mynetworks to include the IP address you are connecting from, or authenticate to the mail server using SASL. Then relaying will work much better.

Also, a good place to start for these matters is often the server's logs. It is rare that they don't include details about why the mail transaction was denied, and they will often point you toward a solution.

share|improve this answer
Thanks. The "relay access denied" message is not appearing anymore. But I can't still send mail. I get this message after sending mail 250 2.0.0 Ok: queued as 9C8404644C but it seems the message is not sent. I get a lot of messages in tail -f /var/log/maillog like this: postfix/error[11760]: C95EC407F4: to=<mymail@gmail.com>, relay=none, delay=261825, delays=261825/0.28/0/0.13, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to alt2.gmail-smtp-in.l.google.com[2607:f8b0:4003:c02::1b]:25: Network is unreachable) –  hpn Feb 21 '13 at 14:26
@hpnik That's a completely separate question, but the first thing I'd verify is the IPv6 connectivity status. (Do you even have an IPv6 WAN link?) Postfix is trying to connect to 2607:f8b0:4003:c02::1b (an IPv6 address) on port 25, but there's no route to that network from your machine. –  Michael Kjörling Feb 21 '13 at 14:28
I changed inet_protocols to ipv4 and this time I get this message: postfix/smtp[14443]: connect to gmail-smtp-in.l.google.com[]:25: Connection timed out. I think it is related to mynetworks now. What I did was adding my ip address to mynetworks. can you explain how do I... "Either connect to your mail server over the loopback interface"? –  hpn Feb 21 '13 at 14:42
@hpnik If the relaying was accepted, then the issue in this question has been resolved. If you are having trouble with the mail server being unable to connect to remote mail servers, that is a different question and such discussion does not really belong in the comments to an answer to the first question. (Remember this is a Q/A site and not a forum.) mynetworks simply controls which IP addresses are considered trusted by Postfix; it has no impact on outbound connections (unless you are doing elaborate configuration magic). mynetworks –  Michael Kjörling Feb 21 '13 at 14:53
OK. thanks. I will open another question for this –  hpn Feb 21 '13 at 14:56
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.