Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System catch emails

Currently i'm building a system (custom CMS) and the requirement is to catch all the emails sent by public to registered email address, and reply via the email address through the system via the registered email as well.

For example:

  1. i set it to [email protected], then when [email protected] sent email to [email protected]
  2. my system will catch it and display the email with attachment to the group
  3. Who handle the email will generate a "randomHashTemp"@stackoverflow.com to identify who handling the case
  4. system will reply via "randomHashTemp"@stackoverflow.com (like google group)
  5. Communicate continue via "randomHashTemp"@stackoverflow.com

BUT

  1. if user sent to [email protected] then will be catch by their current email server like exchange

i don't know the term of this called. May i know how can i implement it? please advice with some links or keywords. i knew a lot of knowledgebase solution, CRM, project management software integrated through CNAME, changing DNS those stuff, but i got no idea on how. Thanks.

Update

The sample would be something like http://www.cloudmailin.com but what i want is generate from my app and receive the emails from public for my clients.

like image 250
1myb Avatar asked Oct 21 '22 15:10

1myb


2 Answers

There are 2 main methods to achieve this

Fetching the email from a mailbox

In this method the email goes to a mailbox and you regularly check for content in this mailbox to process the email. While this generally causes a lag, you can reduce this by running a program regularly and having it poll the mailbox all the time.

Related question

Redirecting mail processing to a program

If your mail server is on unix, you can redirect email processing to a script where you can process the email as you wish

Related question outside SO

Specifically it may be easiest to find a web host that supports procmail scripts. These configuration scripts allow you to redirect email to a PHP program and you can do this as a catchall for all email of a domain. See this example answer

like image 74
jdog Avatar answered Oct 27 '22 11:10

jdog


I've done exactly this with cloudmailin -- you just need to set up mail forwarding for all your public addresses to your cloudmailin address. So:

  1. User emails randomly hashed address at, e.g. [email protected]

  2. Mail server at example.com forwards all mail for info to [email protected].

  3. Cloudmailin posts email to your web site at http://example.com/yourwebhook.php.

  4. Even though all mail is filtering through a single cloudmailin address, cloudmailin will include the original hashed to-address in the fields it posts, so your web site can extract the hash and determine which user is replying. Pseudo-PHP to give you an idea:

    <?php /* webhooks.php */
    $address = $_POST['to']; // '[email protected]'
    $addressParts = explode('@', $address); // array('info+dfj28d', 'example.com')
    $userParts = explode('+', $addressParts[0]); // array('info', 'dfj28d');
    $hash = $userParts[0]; // 'dfj28d'
    ?>
    

In this example I'm using hashes like info+dfj28d because our mail domain was hosted on gmail, so gmail's username+alias syntax was an easy way to send all random hashes to the same mailbox. Other mail hosts have similar methods of creating wildcard aliases.

The point is you need both a random component (dfj28d), and a static component (info) in the address so your mail server can tell the difference between hashed addresses (anything that includes info) and regular mail accounts ([email protected]).

like image 25
Nick Blanchard-Wright Avatar answered Oct 27 '22 10:10

Nick Blanchard-Wright