Score:0

How to force postfix to use smtp relay

fr flag

When I execute, the following line postfix uses my sendgrid relay server

echo "Subject: sendmail test" | sendmail -v [email protected]

But when I execute the sendmail function via the PHP script it won't send it to the relay server. Look like it want to distribute it locally

Any thoughts on how to force postfix to use the smtp relay option

  • Update

It looks like postfix is timing out on STARTTLS, I have added the log below. Could this be due to my LetsEncrypt certificate?

postfix/smtpd[29268]: > localhost[::1]: 250-www.example.com
postfix/smtpd[29268]: > localhost[::1]: 250-PIPELINING
postfix/smtpd[29268]: > localhost[::1]: 250-SIZE 10240000
postfix/smtpd[29268]: > localhost[::1]: 250-VRFY
postfix/smtpd[29268]: > localhost[::1]: 250-ETRN
postfix/smtpd[29268]: > localhost[::1]: 250-STARTTLS
postfix/cleanup[29279]: 8E2B520B98: message-id=<[email protected]>
postfix/smtpd[29268]: smtp_get: EOF

postconf -n

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
header_size_limit = 4096000
inet_interfaces = all
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
mydestination = $myhostname, localhost.$mydomain, localhost
mydomain = example.com
myhostname = www.example.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +
relayhost = smtp.sendgrid.net:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:apikey:BLBAABLAABLAA
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_tls_security_level = encrypt
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname E
SMTP $mail_name (Debian/GNU)
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes

It seems to work perfectly when I write a python script but with the PHP swiftmailer it seems to fail and return an EOF

=============== UPDATE

The relay seems to work but now we are getting this error

Swift_IoException [ 0 ]: Connection to localhost:25 Timed Out

I am able to sendmails using sendmail, but when SwiftMailer is using sendmail its getting the earlier stated error

Richard Olthuis avatar
fr flag
I have debugged a bit more and added the log where I think it times out on.
djdomi avatar
za flag
i think you are looking for `relayhost = gateway.mydomain.tld`
Paul avatar
cn flag
Please post the output of `postconf -n`.
Richard Olthuis avatar
fr flag
I updated the post with the postconf -n
Paul avatar
cn flag
Indeed, it appears you have some problem outside of `postfix`. I think of `smtp` in `postfix` as sending to another server and `smtpd` as receiving from whatever you configure to receive. So, the log entry you posted for `postfix/smtpd` is telling you something wants to be received by `postfix` but there is a problem. I don't know anything about SwiftMailer, but you should look through the configuration of that tool, as it appears to be connecting to the `localhost` `smtp` port and something is going wrong there. BTW, this doesn't mean you don't still need to add something to `postfix` config.
Paul avatar
cn flag
Just a quick note, I always try to send test messages to external addresses and internal ones, especially that have alias to external addresses, such as `root`. Also, SE has changed how these comments work and I seem to no longer receive notification of first comment after my comment unless I am tagged in the comment.
Richard Olthuis avatar
fr flag
Thank you @paul, you made me look at the messages that were send! And I have managed to find the answer
Score:1
fr flag

I managed to fix the issue. It turned out that the mail that the client send out was embedded with an unauthorised image. I removed the embedded image and everything works fine now!

I do find it odd that nothing would show in the verbose log of postfix

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.