gen-smtp / gen_smtp

The extensible Erlang SMTP client and server library.
Other
683 stars 266 forks source link

postfix forwarding #299

Closed mforde84 closed 3 years ago

mforde84 commented 3 years ago

Hello,

Im attempting to forwarding emails sent to postfix server to the smtp server but getting a bounce at the smtp server:

cat /etc/postfix/transport
example.com smtp:mail.example.com:2525
.example.com smtp:mail.example.com:2525

cat /etc/postfix/main.cf
...
smtp_host_lookup = native

cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.128.3.229 mail.example.com example.com

So the host receives the message through localhost:

echo "htello" | mailx -s hello root@example.com

without the forward transport defined, the postfix config works as intended, but once the transport is setup we get a bounce error:

Nov  3 15:25:57 cdvlhbqr242 postfix/smtp[5711]: 2981862D4D: to=<root@example.com>, relay=mail.example.com[10.128.3.229]:2525, delay=0.15, delays=0.02/0.01/0.04/0.07, dsn=5.0.0, status=bounced (host mail.example.com[10.128.3.229] said: 554 Message cannot be delivered (in reply to end of DATA command))

Is there some authentication piece im missing on the gen_smtp end? Or do you have any insights into why gen_smtp server is bouncing messages like this?

seriyps commented 3 years ago

Hi. It would be hard to tell without knowing what code do you have as gen_smtp_server_session callback module (1st argument of gen_smtp_server:start/2)

mforde84 commented 3 years ago

Hey so the info I was able to find in the code was:

10.128.3.228 :: root -> grep gen_smtp_server *
rabbit_email_handler.erl:-behaviour(gen_smtp_server_session).
rabbitmq_email_app.erl:        [{email_handler, {gen_smtp_server, start_link, [rabbit_email_handler, ServerConfig]},

this is an older tier2 plugin for rabbitmq-email. it hasnt been built successfully for a while, and its running an older version of erlang/21.3 and the build for gen_smtp is 0.15.x actually.

so reading the documentation on rabbitmq-email the gen_smtp server configuration is handled through the following advanced.conf

rabbitmq_email.server_config defines SMTP server parameters (same as in gen_smtp)


    {rabbitmq_email, [
      {server_config, [
          [{port, 2525}, {protocol, tcp}, {domain, "example.com"},{auth, never}, {tls, never}, {address,{0,0,0,0}}]
      ]},
      {server_auth, false},
      {server_starttls, false},
...```
lukebakken commented 3 years ago

Note that this syntax is incorrect as it "double lists" the proplist:

      {server_config, [
          [{port, 2525}, {protocol, tcp}, {domain, "example.com"},{auth, never}, {tls, never}, {address,{0,0,0,0}}]
      ]}

It should be:

{server_config, [
    {port, 2525}, {protocol, tcp}, {domain, "example.com"},{auth, never}, {tls, never}, {address,{0,0,0,0}}
]}

I found this while working on - https://github.com/gotthardp/rabbitmq-email/issues/45

mforde84 commented 3 years ago

Ah good catch

On November 11, 2021 3:52:40 PM Luke Bakken @.***> wrote:

Note that this syntax is incorrect as it "double lists" the proplist: {server_config, [ [{port, 2525}, {protocol, tcp}, {domain, "example.com"},{auth, never}, {tls, never}, {address,{0,0,0,0}}] ]}

It should be: {server_config, [ {port, 2525}, {protocol, tcp}, {domain, "example.com"},{auth, never}, {tls, never}, {address,{0,0,0,0}} ]}

I found this while working on - gotthardp/rabbitmq-email#45 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

mforde84 commented 3 years ago

we were able to get the forwarding to work. it was both a postfix config issue, and an issue with the encoding the message relayed to rabbitmq-email plugin

mforde84 commented 3 years ago

technically this ticket can close, unless you want to keep it open for additional tracking purposes. up to you.

seriyps commented 3 years ago

Ah, so the code was actually opensource https://github.com/gotthardp/rabbitmq-email/blob/master/src/rabbit_email_handler.erl

Thanks @lukebakken for your help!