Sign inSign up

notmycloud/smtpsmartrelay

By notmycloud

•Updated about 4 years ago

SMTP Relay to Cloud API providers such as SendGrid.

Image
0

818

notmycloud/smtpsmartrelay repository overview

⁠SMTP Smart Relay

Provides a SMTP that will route through a mail API service. Initial support for SendGrid, others to follow as requested.

Open issues here: https://gitlab.com/notmycloud/smtpsmartrelay⁠

⁠Configuration Notes

Configuration can be set via Environmental Variables, Config File, or command line flags.

The config file should be named smtpsmartrelay.yaml and can be found in the following directories.

  • /etc/smtpsmartrelay/
  • ~/.config/smtpsmartrelay/
  • Current directory (this can be changed using the -config flag.)

Flags are case sensitive and environment variables must be all uppercase and prefixed by SMTP_SMART_RELAY. This prefix is omitted from the below table for formatting purposes. An option with a period in the name designates a subkey in YAML format and periods and dashes should be replaced with underscored for environment variables.

Please reference github.com/emersion/go-smtp for more detail on the server... configuration options.

ENV (Include Prefix of SMTP_SMART_RELAY)FlagConfigDefaultDescription
_CONFIGconfigN/A"."Path to find the smtpsmartrelay.yaml configuration file
_DEBUGdebugdebug:falseEnable debug logging
_SERVER_PORTserver.portserver: port:2525Port for the SMTP server to listen for new messages
_SERVER_DOMAINserver.domainserver: domain:localhostSMTP relay domain, should match the public domain as configured in the relay service
_SERVER_READ_TIMEOUTserver.read-timeoutserver: read-timeout:10sRead timeout for incoming mail.
_SERVER_WRITE_TIMEOUTserver.write-timeoutserver: write-timeout:10sWrite timeout for incoming mail.
_SERVER_MAX_MESSAGE_SIZEserver.max-message-sizeserver: max-message-size:25Maximum size of an email message in Megabytes.
_SERVER_MAX_RECIPIENTSserver.max-recipientsserver: max-recipients10Maximum number of recipients per email.
_SERVER_ALLOW_INSECURE_AUTHserver.allow-insecure-authserver: allow-insecure-auth:falseAllow unencrypted authentication.
_SERVER_ENABLE_SASL_LOGINserver.enable-sasl-loginserver: enable-sasl-login:falseEnable SASL based login. Per this issue⁠ on the supporting package, LOGIN is obsolete.
_SENDGRID_ENABLEsendgrid.enablesendgrid: enable:trueCurrently doesn't do anything, but will be added in the future when we enable additional API services. Only one service can be enabled at a time.
_SENDGRID_API_KEYsendgrid.api.keysendgrid: api: key:""Your private API key for the SendGrid API service.
_SENDGRID_API_HOSTsendgrid.api.hostsendgrid: api: host:https://api.sendgrid.com⁠API domain. (You should not need to change this.)
_SENDGRID_API_ENDPOINTsendgrid.api.endpointsendgrid: api: endpoint:/v3/mail/sendAPI Endpoint. (You should not need to change this.)
_SENDGRID_OVERRIDE_NAMEsendgrid.override.namesendgrid: override: name:falseOverride the name of the email, will use the username from the original address.
_SENDGRID_OVERRIDE_DOMAINsendgrid.override.domainsendgrid: override: domain:""Override the domain of the from address.
_SENDGRID_OVERRIDE_FROMsendgrid.override.fromsendgrid: override: from:""Override the from address in the email.

⁠Basic Configuration

In my case, I registered a subdomain with SendGrid so as to not interfere with my base domain email. I registered sg.domain.com and they show #####.sg.domain.com on my website. In this case, you need to override the domain to sg.domain.com or the API call will fail.

Docker run --name="sendgrid" \
        -e SMTP_SMART_RELAY_SERVER_DOMAIN=sg.domain.com \
        -e SMTP_SMART_RELAY_SERVER_ALLOW_INSECURE_AUTH=TRUE \
        -e SMTP_SMART_RELAY_SERVER_ENABLE_SASL_LOGIN=TRUE \
        -e SMTP_SMART_RELAY_SENDGRID_API_KEY=<SUPERSECRETAPIKEY> \
        -e SMTP_SMART_RELAY_SENDGRID_OVERRIDE_NAME=TRUE \
        -e SMTP_SMART_RELAY_SENDGRID_OVERRIDE_DOMAIN=sg.domain.com \
        -p 2525:2525 \
        -v /etc/localtime:/etc/localtime:ro \
        -v /etc/ssl/certs/:/etc/ssl/certs/:ro \
        registry.gitlab.com/notmycloud/smtpsmartrelay:latest

If you wanted to load the above via a configuration file it would look as follows.

server:
  domain: sg.domain.com
  allow-insecure-auth: true
  enable-sasl-login: true
sendgrid:
  api:
    key: <SUPERSECRETAPIKEY>
  override:
    name: true
    domain: sg.doamin.com

Tag summary

Content type

Image

Digest

sha256:2d89230d5…

Size

3.2 MB

Last updated

about 4 years ago

docker pull notmycloud/smtpsmartrelay