Skip to content

Instantly share code, notes, and snippets.

@samuraisam
Created April 20, 2017 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuraisam/c1528db7f69e54ee9cf64ef95a41e615 to your computer and use it in GitHub Desktop.
Save samuraisam/c1528db7f69e54ee9cf64ef95a41e615 to your computer and use it in GitHub Desktop.
defmodule TestHound.SMTP.Callbacks do
require Logger
defmodule State do
defstruct customer: "Default"
end
@behaviour :gen_smtp_server_session
def init(hostname, sesh_count, address, options) do
Logger.info("Peer: #{hostname} sesh_count #{sesh_count} address #{address} options #{inspect(options)}")
{:ok, "#{hostname} ESMTP smtp_server_callbacks", %State{}}
end
def handle_HELO(hostname, state) do
Logger.info("HELO from #{hostname}")
{:ok, 655360, state}
end
def handle_EHLO(hostname, extensions, state) do
Logger.info("EHLO from #{hostname} extensions #{inspect(extensions)}")
{:ok, [{"AUTH", "PLAIN LOGIN CRAM-MD5"}, {"STARTTLS", true}], state}
end
def handle_MAIL(from, state) do
Logger.info("MAIL From: #{from}")
{:ok, state}
end
def handle_MAIL_extension(extension, state) do
Logger.info("MAIL Extension: #{extension}")
{:ok, state}
end
def handle_RCPT(to, state) do
Logger.info("RCPT To: #{to}")
{:ok, state}
end
def handle_RCPT_extension(extension, state) do
Logger.info("RCPT Extension: #{extension}")
{:ok, state}
end
def handle_DATA(from, to, data, state) do
Logger.info("DATA From: #{from} To: #{inspect(to)} Data: #{data}")
ref = Base.encode16(:crypto.hash(:sha256, data))
{:ok, ref, state}
end
def handle_RSET(state) do
Logger.info("RSET")
{state}
end
def handle_VRFY(address, state) do
Logger.info("VRFY address #{address}")
{:error, "252 VRFY disabled by policy, just send some mail", state}
end
def handle_other(verb, args, state) do
Logger.info("#{String.upcase(verb)} args: #{inspect(args)}")
{"500 Error: command not recognized : #{verb}", state}
end
def code_change(_old_vsn, state, _extra) do
{:ok, state}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment