Email:   Password:
Blog :: Technical Learning by Thomas Riemer
RSS 2.0   RSS 1.0   Atom
Inbound Mail AWS   (PDF)
Posted April 10th, 2024

Amazon AWS limits inbound smtp requests.

If you set up an aws EC2 instance and use an elastic IP - the incoming smtp is blocked.

Don't let anyone kid you - its a fact.    It doesn't matter if you adjust your security group

to allow incoming smtp.

So what is the alternative?

The answer I came up with today is

It allows you to assign mx servers and route your email.

It allows you to route to a specific mailbox AND, AND, AND it allows you to setup

a webhook to post to when emails are sent.

A webhook is a piece of code on a server that accepts a payload.

In this case its a json with the wad of an email each time that someone sends an email

to a particular domain.

The documentation from on the particular json packet sent is non

existent - but it doesn't matter once you see the json.

Ok - so once you get the wad of json - the next thing is to parse the email.

Again this is a piece of arcana that is a bit weak on documentation.

1. php has mailparse - this is a pecl addition to parse mime emails.

2. there is a library that uses the pecl library mailparse.

    php-mime-mail-parser is a php library that supposedly is supported for php 8+

And if you are going to mess with this stuff believe me, you want to be able to have

baseline to test emails with:

Here is a link to a really solid tool to send emails:

Ok, don't forget the implications of a) SPF b) DKIM C) DMARC D) Reverse DNS

Here is sample code for a webhook from that seems to work.

The code depends on a bunch of other stuff - but it should be a good start in

allowing you to grab the data.

function do_inject($path)
      header('Content-Type: application/json');
      $request = file_get_contents('php://input');

      $rand = rand(1000,2000);
      $raw ="/m/member/tmp/incoming.".$rand.".email";
      $parsed = "/m/member/tmp/incoming.".$rand.".parsed";
      require_once "parseinject.php";
      $pi = new parseinject();
      $fields = $pi->parse($request);
      $emailparsed = "";
      foreach ($fields as $key=>$value)
          $emailparsed .= $key."\n";
          $emailparsed .= $value."\n";
          $emailparsed .= "\n";
          $emailparsed .= "\n";
      require_once "background/injector/injectmail.php";
      $imail =new injectmail();
      $imail->source_email = $fields['from'];
      $imail->target_email = $fields['address'];
      $imail->email_content = $fields['raw'];
      $imail->email_size = strlen($fields['html']);
      $imail->queue_reference = $field['messageid'];
      echo "INJECTED";
      http_response_code(200); }

Copyright © 2024 Mind Contract, Inc.   All Rights Reserved
For more information call or email 720-883-1866
Powered By: Build a Member