DEPRECATED - Migrated to https://github.com/mozilla/fxa
Перейти к файлу
Phil Booth f18a5bc60e
chore(code): eliminate some if-lets in favour of combinators
https://github.com/mozilla/fxa-email-service/pull/43
r=vladikoff
2018-06-05 13:23:01 +01:00
config feat(sendgrid): implement basic sending via sendgrid 2018-05-31 17:31:14 +01:00
scripts chore(queues): split out a separate process for queue-handling 2018-05-29 09:01:54 +01:00
src chore(code): eliminate some if-lets in favour of combinators 2018-06-05 13:23:01 +01:00
.gitignore feat(db): check the emailBounces table before sending email 2018-05-16 05:25:08 +01:00
.rustfmt.toml chore(project): inch closer towards the default rustfmt config 2018-05-16 08:34:54 +01:00
.travis.yml chore(project): update rocket, unpin from nightly-2018-05-29 2018-06-01 10:24:13 +01:00
Cargo.lock fix(sendgrid): return message id from the sendgrid provider 2018-06-05 09:15:40 +01:00
Cargo.toml fix(sendgrid): return message id from the sendgrid provider 2018-06-05 09:15:40 +01:00
LICENSE chore(project): add the MPL 2018-05-04 07:14:43 +01:00
README.md feat(sendgrid): implement basic sending via sendgrid 2018-05-31 17:31:14 +01:00
Rocket.toml chore(config): run rocket on port 8001 in dev 2018-05-16 06:57:23 +01:00
r chore(queues): split out a separate process for queue-handling 2018-05-29 09:01:54 +01:00
rq chore(queues): split out a separate process for queue-handling 2018-05-29 09:01:54 +01:00
t chore(queues): split out a separate process for queue-handling 2018-05-29 09:01:54 +01:00
tdb chore(queues): split out a separate process for queue-handling 2018-05-29 09:01:54 +01:00

README.md

fxa-email-service

Build status License Under construction

What's this?

The FxA team have an OKR for Q2 2018 about decoupling the auth server from SES and making it possible to send email via different providers. You can read more about that OKR in the feature doc.

This repo is our experiment to see what a decoupled email-sending service would look like. It's being written in Rust.

Moving to a new service seems risky. How will that work?

As a first step, we're doing a like-for-like extraction of functionality from the auth server and porting it to Rust behind a very simple, single-endpoint API. The plan is to run it on a closed port on the same box as the auth server, similar to how we run the auth db server.

Included in the code earmarked for extraction is the logic for handling bounce, complaint and delivery notifications. Because this logic is stateful, the initial plan is for the new service to lean on the db server directly and re-use the same table and stored procedures that are already being used. So in that sense, the switchover should be transparent and we can even run the new service side-by-side with the current auth server, if we want to phase it in gradually.

What are the long-term goals?

Ultimately, if everything goes to plan, we'd like to run this as a standalone service that can be used by other trusted reliers from the Firefox/Application Services ecosystem. But getting to that point will require a number of features that are out of scope for the initial release, such as authentication, rate-limiting and a dedicated database.

How will you make sure the new service isn't just as tightly coupled to SES?

The core functionality is going to be exposed behind traits and we will limit the AWS-specific code to AWS-specific trait implementations. To keep ourselves honest about that separation, we will also implement an alternative provider that email can be routed by on a per-request basis.

How can I set up a dev environment?

We're running on the Rust nightly channel, so the easiest way to get set up is with rustup:

curl https://sh.rustup.rs -sSf | sh

If you don't want to use nightly as your default channel, you can use it just for this repo instead by installing nightly and then running rustup override in this directory:

rustup install nightly
rustup override set nightly

How do I run the tests?

A simple cargo t will fail because some of the tests are not threadsafe (they rely on setting environment variables that will conflict with other concurrent tests). To run the tests in a single thread instead, a shell script is provided to save you some keystrokes:

./t

That script assumes you have an instance of fxa-auth-db-mysql running locally on port 8000, which will be the case if you're running fxa-local-dev.

If that's not the case, don't worry. There is another script provided to save you even more keystrokes:

./tdb

That script will clone a local copy of the db repo and start it in the background. At the end of the script, the db process will be left running in the background (but subsequent runs of the script won't start extra db processes, you'll only be left with that one). If you want to kill your db process, you can find it with:

ps -ef | grep "node bin/server"

How can I send an email via SES?

You'll need to set up some config with your AWS credentials. That can be with environment variables:

  • FXA_EMAIL_SES_KEYS_ACCESS
  • FXA_EMAIL_SES_KEYS_SECRET

Or in config/local.json:

{
  "ses": {
    "keys": {
      "access": "...",
      "secret": "..."
    }
  }
}

config/local.json is included in .gitignore, so you don't have to worry about your keys being accidentally leaked on GitHub.

Also note that the AWS IAM limits sending to approved from addresses. Again, you can set that via environment variables:

  • FXA_EMAIL_SENDER_ADDRESS
  • FXA_EMAIL_SENDER_NAME

Or in config/local.json:

  "sender": {
    "address": "verification@latest.dev.lcip.org",
    "name": "Firefox Accounts"
  },

Once you have config set, you can start the service with:

cargo r --bin service

Then you can use curl to send requests:

curl \
  -d '{"to":"foo@example.com","subject":"bar","body":{"text":"baz"}}' \
  -H 'Content-Type: application/json' \
  http://localhost:8001/send

If everything is set-up correctly, you should receive email pretty much instantly.

How can I send an email via Sendgrid?

The process is broadly the same as for SES. First set your Sendgrid API key, either using the FXA_EMAIL_SENGRID_KEY environment variable or in config/local.json:

{
  "sendgrid": {
    "key": "..."
  }
}

Then start the service:

cargo r --bin service

Then set provider to sendgrid in your request payload:

curl \
  -d '{"to":"foo@example.com","subject":"bar","body":{"text":"baz"},"provider":"sendgrid"}' \
  -H 'Content-Type: application/json' \
  http://localhost:8001/send

If everything is set-up correctly, you should receive email pretty much instantly.