Postal: Use External SMTP Relays

Created on 28 Apr 2017  路  21Comments  路  Source: postalhq/postal

It would be nice to be able to configure Postal to use a set of external email relays rather than rely on the internal SMTP implementation and IP Pools.

This would allow separation of the actual delivery infrastructure from Postal and allow Postal to become more of an "interface" to send, receive and administrate email. It would also allow Postal to be "dropped" on top of existing installations and work out of the box without too much reconfiguration.

In our use case, we already have a large email delivery infrastructure in place that uses multiple Postfix servers and a SMTP load balancer. We'd like to keep this installation in place, along with their relatively complex configurations that have evolved over the years, but use Postal as an interface to this to allow sending email via HTTP and SMTP, but also give much greater insight into what and how much email is being sent and delivered. We currently aggregate this information from mail logs and display it on a Grafana dashboard.

I'd imagine this could be implemented as an extension of the current IP Pools functionality. If this is something you'd be open to, I'm happy to work on a PR to get this merged in.

Most helpful comment

You'll need to be more specific than "kind of" if you are looking for any valuable advice.

Postal does not support this out of the box, so the best bet is to augment it with a local mail relay. The general idea is to setup a local SMTP relay that accepts mail (without authentication) on 127.0.0.1. Configure Postal to use this SMTP relay. Then, in the local SMTP relay, configure it to relay mail to your external SMTP relay that requires authentication, and configure your authentication in there.

_Note: With this setup, you'll lose almost all visibility into sending statistics, as the local mail relay will queue, drop and manage the email separate from Postal._

Using postfix as an example, you can configure a relayhost (and proper access control) in your main.cf. For example:

relayhost = [smtp.sendgrid.net]:587

# Only allow relaying mail from the local machine
mynetworks = 127.0.0.0/8, [::1]/128
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

Then, you can configure a SASL authentication file that holds the username and password for your SMTP relay:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

Your /etc/postfix/sasl_passwd file would look something like:

[smtp.sendgrid.net]:587 username:password

Of course this all depends on your installation and requirements, and one would hope that if you were going down this path, you knew what you were doing and would know what all of the mentioned configuration options do. The last thing we need is another open mail relay on the internet! 馃槃

All 21 comments

I have added support for relaying outgoing SMTP through external hosts (except in the case when an incoming e-mail is forwarded to another SMTP server). By doing this, however, you will lose some functionality from Postal (including the suppression list).

To configure SMTP relay hosts you can add the following to your config file:

smtp_relays:
  -
    hostname: othersmtp.yourdomain.com
    port: 25
    ssl_mode: Auto

ssl_mode can be None, Auto, STARTTLS or TLS. Same as the options available when configuring an SMTP endpoint for incoming e-mail.

You can add as many relays as you want. They will be tried in order until accepted.

Please give this a go and let me know how you get on.

What about authentication on SMTP relays?

That isn't supported. You should configure your relay to allow connections from the IP of your Postal server.

Hello We arrying to relay outbound emails from Postal to another server. The main reason is that with postal we cannot manage the VMTAs like we can with PowerMTA. We have tried the code below:

smtp_relays:
hostname: othersmtp.yourdomain.com
port: 25
ssl_mode: Auto
We have tried to configure 10 SMTP relays but none is working. We have disabled username and password. The SMTP for POstal Emails is working perfectly.

HOw can we achieve this?

@brainiers did you find any things about SMTP relays authentication

@Manishjodhani You should be using whitelists for your authentication. Allow your SMTP relay to accept mail unauthenticated from your Postal server's IP address.

If you are trying to relay email via Gmail (or other consumer mail relays that require authentication), I would highly recommend you seek an alternative. They are not designed to be used for this use case, and you'll most likely get your account throttled or banned.

If you really _MUST_ have authentication to an external SMTP relay (eg. SendGrid or another platform designed for delivering transactional/bulk email) then you can setup a local mail relay without authentication on your Postal server (something like sendmail), and then configure it to relay mail via your external mail relay with authentication. I have configured a Postal install with this setup, and it works surprisingly well, albeit with higher maintenance.

"then configure it to relay mail via your external mail relay with authentication." what do you mean by this...???
I use as smtp relays like postfix or pmta. In config file there is no define of authentication.
Is there any method to get authentication by programming in postal..that's it.... i really want to know yes or no ??

I'm not sure what question you are asking anymore. Are you trying to authenticate with an external mail relay?

Yes....kind of

You'll need to be more specific than "kind of" if you are looking for any valuable advice.

Postal does not support this out of the box, so the best bet is to augment it with a local mail relay. The general idea is to setup a local SMTP relay that accepts mail (without authentication) on 127.0.0.1. Configure Postal to use this SMTP relay. Then, in the local SMTP relay, configure it to relay mail to your external SMTP relay that requires authentication, and configure your authentication in there.

_Note: With this setup, you'll lose almost all visibility into sending statistics, as the local mail relay will queue, drop and manage the email separate from Postal._

Using postfix as an example, you can configure a relayhost (and proper access control) in your main.cf. For example:

relayhost = [smtp.sendgrid.net]:587

# Only allow relaying mail from the local machine
mynetworks = 127.0.0.0/8, [::1]/128
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

Then, you can configure a SASL authentication file that holds the username and password for your SMTP relay:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

Your /etc/postfix/sasl_passwd file would look something like:

[smtp.sendgrid.net]:587 username:password

Of course this all depends on your installation and requirements, and one would hope that if you were going down this path, you knew what you were doing and would know what all of the mentioned configuration options do. The last thing we need is another open mail relay on the internet! 馃槃

Thanks for this
I will try this on postfix.
And but in pmta there is no SASL Authentication.So what about in Pmta ???

I don't use PMTA so I can't help you there, I'd recommend you look into their documentation on how to authenticate with mail relays. It looks like this SO answer has the correct configuration syntax, but I'm not sure how correct or applicable this is as I've never used PMTA before.

Thanks @jduncanator
You were telling this pmta >> external smtp
but i want to do this postal >>external smtp (PMTA)
??

How will the bounce data reflect in the postal dashboard?

@rsgehlot From my understanding, bounce data depends on the Return-Path header of the email. So long as the Return-Path email address is setup (and you have setup incoming email for Postal) the bounce data should still get tracked correctly when using an external SMTP relay.

Hello,

Sorry to open again this issue. Is it possible to relay over API on POSTAL? My topology like below :

Postal -> Relay to External server using API -> My Server Application

On my server application (like newsletter server/mail campaign), we have some information like :

  • email open
  • email sent
  • email click link
  • email bouncing
  • Graphic
  • Client access to check report

My goal is to records all email that sent from client to my application server. Maybe the topology like below :

Email server on my client -> Relay to Postal using Auth -> Postal relay to my application using API -> My application records all email that sent from Postal

@imanudin11 You shouldn't need to relay mail _into_ your application. You should be able to access the appropriate information _from_ your application via the Postal API.

If the Postal API doesn't expose enough of the information you'd like, then I'd recommend opening a feature request for those features to be added to Postal.

Alternatively, you could implement an SMTP server in your application that listens on the SMTP port, and then set Postal up to relay email there.

As a comment on your initial request, I don't think it is inside the scope of Postal to support arbitrary external application APIs, as your API is likely different from the next persons, who is different from the next persons. Perhaps this could be resolved by some sort of Webhook functionality being added to Postal, that allows specific information about certain events in Postal being POSTed to an external application by means of a web request? That said, this is the topic for another issue...

Hello @jduncanator ,

Thanks for your information and advice. I've tried to install SMTP on my application server. But, every email that sent from the SMTP, not recorded on my application. Such as from, subject, to and etc.

I need a feature like Postal. That have SMTP and all email transaction recorded on the web application.

I see Postal have own SMTP server. Not Postfix or Sendmail that familiar to me :)

Postal can either send email for a domain that is configured to anywhere or receive email for a domain that is configured from anywhere but I'm not sure if that fits your requirements exactly.

Have a look at the Routes tab in your Postal and if you have any more questions, please open a new issue.

Postal can either send email for a domain that is configured to anywhere or receive email for a domain that is configured from anywhere but I'm not sure if that fits your requirements exactly.

Have a look at the Routes tab in your Postal and if you have any more questions, please open a new issue.

Hy will,
I want to know how i can set routes in my postal mail server. I want all incoming emails on that server to another domain email.
Like i am using domain1.com for sending email and domain1.com is linked with postal in domain DNS.
I want to receive replies of all emails from that domain1.com sending using postal mail server on domain2.com mail server that is on godaddy shared server.
How i can route incoming email to domain2.com emails ???

What entires I need to exactly put in Routes and what are for SMTP Endpoints ??

and please share the solution with the real values that i need to put in the route and SMTP endpoints sections.

As i tried almost everything in this and still receiving of emails if not working.

Thanks in advance for this.

@karankashyap208 each endpoints page has a short description of what it does if you haven't added any entries, routes connect incoming email messages to the endpoints. It sounds like you need an address endpoint for domain2.com. Please open a new issue if you are stuck rather than commenting on old issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

giezi picture giezi  路  7Comments

shinebayar-g picture shinebayar-g  路  3Comments

moskoweb picture moskoweb  路  6Comments

igerzog picture igerzog  路  5Comments

Igcorreia picture Igcorreia  路  4Comments