Git Product home page Git Product logo

aws-smtp-relay's Introduction

aws-smtp-relay

[DEPRECATED] I moved to this project instead: https://github.com/loopingz/smtp-relay It should have similar features with more flexibility, please create issue on the new project

logo

Current main:

CodeQL CI

Local SMTP server that convert SMTP message to AWS SES API Call to allow you to use AWS Role Instance.

If you follow the AWS SES postfix relay : http://docs.aws.amazon.com/ses/latest/DeveloperGuide/postfix.html

You can have a simple relay for your email, this issue with it is you have to create SMTP credentials.

To follow AWS Best practices you need to rotate those keys at least every 90 days, so the AWS Role are easier to use.

Sending an email with Postfix relay looks like this :

Postfix Schema

Sending an email with aws-smtp-relay looks like this : aws-smtp-relay Schema

Compile

Just run the maven project

git clone https://github.com/loopingz/aws-smtp-relay.git
cd aws-smtp-relay
mvn clean compile assembly:single

Run

Take the result of your compilation or download the static jar here

java -jar aws-smtp-relay.jar

By default the SMTP run on port 10025

Arguments

usage: aws-smtp-relay
 -a,--sourceArn <arg>          AWS Source ARN of the sending authorization policy
 -b,--bindAddress <arg>        Address to listen to
 -c,--configuration <arg>      AWS SES configuration to use
 -f,--fromArn <arg>            AWS From ARN of the sending authorization policy
 -p,--port <arg>               Port number to listen to
 -r,--region <arg>             AWS region to use
 -al --authLambda <arg>        Name of AWS Lambda to invoke for authentication
 -smtpH,--smtpHost <arg>       SMTP variable Host
 -smtpO,--smtpOverride <arg>   Not use SES but set SMTP variables t/f true/false
 -smtpP,--smtpPort <arg>       SMTP variable Port
 -smtpU,--smtpUsername <arg>   SMTP variable Username
 -smtpW,--smtpPassword <arg>   SMTP variable password
 -ssm,--ssmEnable              Use SSM Parameter Store to get configuration
 -ssmP,--ssmPrefix <arg>       SSM prefix to find variables default is /smtpRelay
 -ssmR,--ssmRefresh <arg>      SSM refresh rate to reload parameter
 -t,--returnPathArn <arg>      AWS Return Path ARN of the sending authorization policy
 -h,--help                     Display this help

"/smtpRelay" can be changed with -ssmP

smtpOverride allows you to point it to a mail catcher such as MailHog to disable outbound email

If ssm (Simple Systems Manager) Parameter store is used please add to your region https://ap-southeast-2.console.aws.amazon.com/systems-manager/parameters once setup, you can change the configuration by restarting the service or rebooting the ec2 instance

                /smtpRelay/region 
                /smtpRelay/configuration 
                /smtpRelay/sourceArn 
                /smtpRelay/fromArn
                /smtpRelay/smtpOverride
                /smtpRelay/smtpHost
                /smtpRelay/smtpPort
                /smtpRelay/smtpUsername
                /smtpRelay/smtpPassword

"/smtpRelay" can be changed with -ssmP/--ssmPrefix

smtpOverride allows you to point it to a mail catcher such as MailHog to disable outbound email

Docker hub

You have a Docker image available

docker run -p 10025:10025 loopingz/aws-smtp-relay

IAM Policy

Use this IAM Policy JSON to allow sending emails.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "ses:SendRawEmail",
      "Resource": "*"
    }
  ]
}

IAM Policy for SSM Paramater store access

Use this IAM Policy JSON to allow SSM Paramater variables to be used instead of the command line Replace $SSMKEY with KMS key arn for the alias aws/ssm i.e. arn:aws:kms:ap-southeast-2:111222333444:key/111111111-2222-3333-4444-555555555555

{
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ssm:DescribeParameters"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "ssm:GetParameters",
        "ssm:GetParameter",
        "ssm:GetParametersByPath"
      ],
      "Resource": [
        "arn:aws:ssm:*:*:parameter/smtpRelay",
        "arn:aws:ssm:*:*:parameter/smtpRelay/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "kms:Decrypt"
      ],
      "Resource": [
        "$SSMKEY"
      ]
    }
  ]
}

Changelog

  • argument --smtpPW is now --smtpW
  • SSM refresh rate to reload parameter added (-ssmR,--ssmRefresh <arg>)
  • AWS From ARN of the sending authorization policy added (-f,--fromArn <arg>)

aws-smtp-relay's People

Contributors

8llouch avatar basschipper avatar dependabot-preview[bot] avatar dependabot[bot] avatar duttonw avatar ebukoski avatar harisiva-codaio avatar loopingz avatar mjohnson9 avatar morganchristiansson avatar pgmillon avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

aws-smtp-relay's Issues

Code offer: init scripts

Expected behavior

Starting and stopping the SMTP relay on machine start/stop.

Actual behavior

Steps to reproduce the behavior

/usr/local/sbin/start-aws-smtp-relay.sh:

#!/bin/sh
PIDFILE=/var/run/aws-smtp-relay.pid
if [ -e $PIDFILE ]; then
  echo "Found $PIDFILE - relay already running?"
  ps -p `head -1 $PIDFILE` > /dev/null && exit 1 || echo "Relay process not found; starting..."
fi

java -jar /usr/share/aws-smtp-relay/aws-smtp-relay-1.0.0-jar-with-dependencies.jar -r us-east-1 &
echo $! > $PIDFILE

/usr/local/sbin/stop-aws-smtp-relay.sh:

#!/bin/sh
PIDFILE=/var/run/aws-smtp-relay.pid
if [ -e $PIDFILE ]; then
  head -1 $PIDFILE | xargs kill
  rm $PIDFILE
fi

/etc/init.d/aws-smtp-relay:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          aws-smtp-relay
# Required-Start:    $remote_fs $network $named
# Required-Stop:     $remote_fs
# Default-Start:     3 4 5
# Default-Stop:      0 1 2 6
# Short-Description: Relay SMTP traffic to AWS SES
# Description:       Mail relay to convert SMTP traffic to Amazon Simple Email Service API calls.
### END INIT INFO

PIDFILE=/var/run/aws-smtp-relay.pid
case $1 in
  start)
    /bin/sh /usr/local/sbin/start-aws-smtp-relay.sh
  ;;
  stop)
    /bin/sh /usr/local/sbin/stop-aws-smtp-relay.sh
  ;;
  status)
    if [ -e $PIDFILE ]; then
      PID=`head -1 $PIDFILE`
    fi
    if [ "$PID" == "" ]; then
      echo "AWS SMTP relay is not running"
    else
      echo "AWS SMTP relay is running with PID $PID"
    fi
  ;;
  restart)
    /bin/sh /usr/local/sbin/stop-aws-smtp-relay.sh
    /bin/sh /usr/local/sbin/start-aws-smtp-relay.sh
  ;;
esac
exit 0

This could also be adapted to replace the default mail sender, of course, by setting the port to 25 and disabling the other sender.

SourceArn support

Is there a possiblity of adding (optional) support for sourceArn when sending emails?

Docker Logs more verbose

Hi,

Is it possible to have more detail in the logs?
such as :

  • the emails incoming,
  • emails outcoming,
  • email failing,
  • email successfull

Thank you

Segfault when trying to send email

Reproduction scenario:

$ docker run -it --rm ubuntu:xenial
root@d260a71663c1:/# apt install -y telnet wget openjdk-8-jdk-headless
root@d260a71663c1:/# wget https://github.com/loopingz/aws-smtp-relay/releases/download/v1.2.0/aws-smtp-relay_1.2.0_all.deb
root@d260a71663c1:/# apt install -y ./aws-smtp-relay_1.2.0_all.deb
root@d260a71663c1:/# /usr/bin/aws-smtp-relay -b 127.0.0.1 -p 25
[main] INFO org.subethamail.smtp.server.SMTPServer - SMTP server /127.0.0.1:25 starting
[org.subethamail.smtp.server.ServerThread /127.0.0.1:25] INFO org.subethamail.smtp.server.ServerThread - SMTP server /127.0.0.1:25 started
Segmentation fault (core dumped)
root@d260a71663c1:/# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 d260a71663c1 ESMTP SubEthaSMTP null
HELO void.com
250 d260a71663c1
mail from: [email protected]

The application crashes in the docker container

Steps to reproduce the behavior

starting the docker container and sending email requests leads to application crash with the following log:

at com.amazonaws.regions.AwsRegionProviderChain.<clinit>(AwsRegionProviderChain.java:33)
at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:347)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:267)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:232)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.amazonaws.client.builder.AwsClientBuilder.<clinit>(AwsClientBuilder.java:60)
at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:347)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:267)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:232)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:232)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.loopingz.AwsSmtpRelay.deliver(AwsSmtpRelay.java:38)
at org.subethamail.smtp.helper.SimpleMessageListenerAdapter$Handler.data(SimpleMessageListenerAdapter.java:142)
at org.subethamail.smtp.command.DataCommand.execute(DataCommand.java:64)
at org.subethamail.smtp.server.RequireTLSCommandWrapper.execute(RequireTLSCommandWrapper.java:30)
at org.subethamail.smtp.server.CommandHandler.handleCommand(CommandHandler.java:99)
at org.subethamail.smtp.server.Session.runCommandLoop(Session.java:244)
at org.subethamail.smtp.server.Session.run(Session.java:145)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)

Exception in thread "pool-2-thread-1" java.lang.NoClassDefFoundError: org.apache.commons.logging.LogFactory
at org.apache.commons.logging.LogFactory.class$(LogFactory.java:847)
at org.apache.commons.logging.LogFactory.(LogFactory.java:1717)
at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:347)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:267)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.amazonaws.regions.AwsRegionProviderChain.(AwsRegionProviderChain.java:33)
at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:347)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:267)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:232)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.amazonaws.client.builder.AwsClientBuilder.(AwsClientBuilder.java:60)
at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:347)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:267)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:232)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:232)
at java.lang.Class.ensureInitialized(DynamicHub.java:437)
at com.loopingz.AwsSmtpRelay.deliver(AwsSmtpRelay.java:38)
at org.subethamail.smtp.helper.SimpleMessageListenerAdapter$Handler.data(SimpleMessageListenerAdapter.java:142)
at org.subethamail.smtp.command.DataCommand.execute(DataCommand.java:64)
at org.subethamail.smtp.server.RequireTLSCommandWrapper.execute(RequireTLSCommandWrapper.java:30)
at org.subethamail.smtp.server.CommandHandler.handleCommand(CommandHandler.java:99)
at org.subethamail.smtp.server.Session.runCommandLoop(Session.java:244)
at org.subethamail.smtp.server.Session.run(Session.java:145)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)

SSL connection

Hi,

I would like to know if it is possible to setup a SSL connection between the client mail and aws-smtp-relay?

If yes,
How can I do it?

Thank you

Version bumps required for several dependencies

In attempting to compile this project according to the instructions in the readme, I observed that the OWASP dependency_check_maven plugin was having trouble grabbing CVE data from NIST (their CVE feed was scuttled a while ago). I bumped the version of this plugin up to 7.0.0 (the most current version available), and re-ran the build. But it failed, after detecting a number of dependencies with known vulnerabilities: I will paste the list below. All of these dependencies, including the dependency_check_maven plugin, need version bumps.

[ERROR] One or more dependencies were identified with vulnerabilities that have a CVSS score greater than or equal to '4.0': [ERROR] [ERROR] commons-cli-1.4.jar: CVE-2021-40111(6.5), CVE-2021-40110(7.5), CVE-2021-38542(5.9), CVE-2021-40525(9.1) [ERROR] commons-io-2.6.jar: CVE-2021-29425(4.8) [ERROR] httpclient-4.5.9.jar: CVE-2020-13956(5.3) [ERROR] jackson-annotations-2.6.0.jar: CVE-2018-1000873(6.5) [ERROR] jackson-core-2.6.7.jar: CVE-2018-1000873(6.5) [ERROR] jackson-databind-2.6.7.3.jar: CVE-2017-17485(9.8), CVE-2018-5968(8.1), CVE-2017-15095(9.8), CVE-2019-16942(9.8), CVE-2020-35491(8.1), CVE-2019-16943(9.8), CVE-2020-25649(7.5), CWE-611: Improper Restriction of XML External Entity Reference ('XXE')(5.4), CVE-2020-35490(8.1), CVE-2019-20330(9.8), CVE-2020-10673(8.8), CVE-2018-11307(9.8), CVE-2018-1000873(6.5), CVE-2018-7489(9.8), CVE-2019-17267(9.8), CVE-2019-17531(9.8), CVE-2019-16335(9.8), CVE-2019-14893(9.8), CVE-2019-14540(9.8) [ERROR] [ERROR] See the dependency-check report for more details.

Docker: Invalid jar

Thanks for publishing on docker hub, however:

$ docker run loopingz/aws-smtp-relay
Error: Invalid or corrupt jarfile /usr/share/aws-smtp-relay/aws-smtp-relay.jar

Thanks 😃

From: header required in DATA command

Getting this error when using an application e-mail alerts.

Exception in thread "pool-1-thread-28330" com.amazonaws.services.simpleemail.model.AmazonSimpleEmailServiceException: Missing required header 'From'. (Service: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidParameterValue; Request ID: xxxxxx)

The program sends from header like this.

MAIL FROM:<[email protected]>

This is not accepted by aws ses which also requires a From: <[email protected]> header in the e-mail or it rejects the API call with the above error.

Will be working to resolve this now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.