Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Commit

Permalink
feat: Use custom FROM email, defined in env (#49)
Browse files Browse the repository at this point in the history
* feat: Use custom FROM email, defined in env

* Add release version in Sentry (fix #48)

* Bigger buffer for e2e test

* Add env in e2e test
  • Loading branch information
amaury1093 authored May 9, 2020
1 parent 130e18f commit ea31e4a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ This repo holds the backend for [Reacher](https://reacherhq.github.io/). The bac

The OpenAPIv3 specification of this backend can be seen on [StopLight](https://stoplight.io/p/docs/gh/reacherhq/backend).

## Get Started

To run the server, just run:

```bash
cargo run
```

The server will then be listening on `http://127.0.0.1:8080`.

These are the environment variables used to configure the HTTP server:

| Env Var | Required? | Description |
| ---------------- | --------- | ------------------------------------------------------------------ |
| `RCH_FROM_EMAIL` | Yes | The email to use in the `MAIL FROM:` SMTP command. |
| `RCH_PROXY_HOST` | No | Use the specified SOCKS5 proxy host to perform email verification. |
| `RCH_PROXY_PORT` | No | Use the specified SOCKS5 proxy port to perform email verification. |
| `RCH_SENTRY_DSN` | No | [Sentry](https://sentry.io) DSN used for bug reports. |

## See also

- [`check-if-email-exists`](https://github.com/amaurymartiny/check-if-email-exists): Rust library to check if an email address exists without sending any email.
2 changes: 1 addition & 1 deletion scripts/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
set -e

# Run reacher, assumes the binary is in ./target/release
./target/debug/reacher &
RCH_FROM_EMAIL=user@example.org ./target/debug/reacher &
sleep 5

# Do some simple curl requests
Expand Down
11 changes: 7 additions & 4 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use check_if_email_exists::{check_email as ciee_check_email, CheckEmailInput, CheckEmailOutput};
use sentry::protocol::{Event, Value};
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, convert::Infallible, env};
use std::{borrow::Cow, collections::BTreeMap, convert::Infallible, env};
use warp::http::StatusCode;

/// JSON Request from POST /check_email
Expand All @@ -38,13 +38,14 @@ fn log_error(

let mut extra = BTreeMap::new();
extra.insert(
"CheckEmailInput".into(),
"CheckEmailOutput".into(),
Value::String(format!("{:#?}", result)),
);

sentry::capture_event(Event {
extra,
message: Some(message),
release: env::var("CARGO_PKG_VERSION").ok().map(Cow::from),
..Default::default()
});

Expand All @@ -61,8 +62,10 @@ pub async fn check_email(body: EmailInput) -> Result<impl warp::Reply, Infallibl
// Create EmailInput for check_if_email_exists from body
let mut input = CheckEmailInput::new(vec![body.to_email]);
input
.from_email(body.from_email.unwrap_or_else(|| "user@example.org".into()))
.hello_name(body.hello_name.unwrap_or_else(|| "example.org".into()));
.from_email(body.from_email.unwrap_or_else(|| {
env::var("RCH_FROM_EMAIL").expect("You must set a RCH_FROM_EMAIL env var.")
}))
.hello_name(body.hello_name.unwrap_or_else(|| "gmail.com".into()));

// If relevant ENV vars are set, we proxy.
if let (Ok(proxy_host), Ok(proxy_port)) =
Expand Down

0 comments on commit ea31e4a

Please sign in to comment.