How to automate sending e-mail when specific message is received?

0

I use Buxfer.com app for money management. This service allows to report expenses by sending an email to a special, private email address assigned to user by Buxfer.

The format required to report an expense, income or transfer is:

<description> [+]<amount> [tags:<tags>] [acct:<account>] [from:<account>] [to:<account>] [date:<date>] [status:<status>] [memo:<memo>]

Elements in [squared brackets] are optional. Text can be written in title field or in message content.

Examples:

coffe 5.45

The simplest example with minimum information required to process the request. Expense: 5.45 from default account, description: "coffee".

coffee 5.45 tags:drinks,coffee acct:amex

Expense: 5.45 on coffee from 'Amex' account, attached tags: 'drinks' and 'coffee'

Pay check +6952.32 status:pending

Income: a pay check of 6952.32. The check is yet to clear

ATM withdrawal 200 from:BoA Checking to:Cash

Transfer: withdrew 200 from a Bank of America ATM into wallet

After each transaction I receive e-mail notification from bank. The sample e-mail looks like this:

from: info@equabank.cz
to: [myemail]@gmail.com
topic: Payment card transaction

Dear Mr. [Surname],

on 05.11.2017 at 10:08 a transaction was performed on your payment card in the amount of 536.80 CZK. Payment detail: KOSIK RETAIL S.R.O.>PRAHA 9 CZ.

For more information, please visit your internet banking.

Equa bank


[...]

I'm looking for a solution to automatically process incoming e-mail, read the information about transaction and send e-mail to predefined adress from Buxfer.

The desired output in this example is:

from: [myemail]@gmail.com
to: [privateemail]@buxfer.com
topic: KOSIK RETAIL S.R.O.>PRAHA 9           CZ 536.80

My available hardware is:

  • notebook with Windows 10,
  • RaspberryPi 3B with Ubuntu Mate 16.04 LTS,
  • smartphone with Android 7.1.2 (AOSP Extended 4.6)

I tried to do this with filter rules in Gmail and Thunderbird; to find add-on to Thunderbird which could do that; searched the web to find appropiate software, but I found only tools for batch sending bulk e-mails, e-mail forwarding or automatic replies.

Sebastian

Posted 2017-11-28T14:20:38.380

Reputation: 21

Answers

2

IFTTT and similar web based services for online automation and integration can be used to automate this process. IFTTT Platform provides wide range of available services with possibility to customise actions in JavaScript (technically TypeScript) in "Filter code" which is executed after Trigger ("if") and before Action ("then"), however it is required to create own applet.

As a Trigger I chose Gmail service and selected New email in inbox from "info@equabank.cz"

As an Action I chose Gmail again and selected "Send an email" to Buxfer account email and configured following fields:

  • Subject: {{Subject}}
  • Body: {{BodyPlain}}

After adding action it was possible to write Filter code which allowed to retrieve amount with description from mail message and format them in required way (description, space, amount). It was necessary to remove any special characters because in sent email they have been converted to HTML symbols. However, Buxfer parsed incoming emails as plain text and treated semi-colon (;) at the end of any special character as beginning of new transaction, according to "documentation":

You can send report multiple expenses in a single message by typing each on a separate line, or separating them with a semi-colon (;)

if (Gmail.newEmailFrom.Subject === "Payment card transaction") {
  var body = Gmail.newEmailFrom.BodyPlain;
  var lines = body.split("\n\n");
  var targetLine = lines[1];
  var words = lines[1].split(" ");
  var amount = words[16];
  var description = targetLine.substring(
    targetLine.lastIndexOf("Payment detail: ") + 16
    );

  description = description.replace(/[^\w\s:]/gi, ' ');
  var targetBody = description + amount;

  Gmail.sendAnEmail.setBody(targetBody);
} else if (Gmail.newEmailFrom.Subject === "Incoming payment to your account") {
  ...
} else if (Gmail.newEmailFrom.Subject === "Outgoing payment from your account") {
  ...
} else {
  Gmail.sendAnEmail.skip()
}

Currently this solution works well with payment card transactions. Tracking incoming payments would require handling multiple accounts. Outgoing payments would need to solve the problem with accounting card payments.

Sebastian

Posted 2017-11-28T14:20:38.380

Reputation: 21

0

I can respond in relation to Unix, here Ubuntu.

You need a local MTA (mail tranfer agent) like "sendmail", configured in the necessary manner, especially concerning the secure protocols to use and concerning your authentication to the remote site. Then you have to build the message to send using a simple text editor or any tool which can produce simple text. Once your message is build, you can simply supply it to "sendmail", which will send it to the recipient. If configured appropriately, "sendmail" can make all the authentication.

In order to process the incoming messages, you could install and configure "fetchmail", which can retrieve the messages from the remote server using the appropriate protocol. Considering that you will probably receive numerous messages, not only related to this payment system, you will have to filter the incoming messages. "procmail" is probably a good tool to help you on this task.

I confess that the configuration of these tool is not at the beginner level.

Claude Frantz

Posted 2017-11-28T14:20:38.380

Reputation: 154

Thank you for advicing me Linux tools, I'll try to look at them further, but I still don't see the way to connect fetchmail and sendmail, I mean: how to get info from incoming mail, put it into correctly formatted text and pass it to sendmail – Sebastian – 2017-11-28T18:54:34.327

In the usual config manner, fetchmail pushes incoming messages to sendmail for delivery to the local mailboxes. – Claude Frantz – 2017-11-29T20:02:30.720

In the usual config manner, fetchmail pushes incoming messages to sendmail for delivery to the local mailboxes. The message to send, should have a From:, a To:, a Subject: lines, then an empty line and the contains of the message. Finally use "sendmail -G -t < messagefile" to supply the message to sendmail. – Claude Frantz – 2017-11-29T20:09:20.770

-1

You need a POP/IMAP server on your mail server so you can receive emails on your local machine. On a Linux machine I recommend Dovecot. To automate the operation fetchmail will do the rest.

HelpBox

Posted 2017-11-28T14:20:38.380

Reputation: 1