Send static confirmation email.

This commit is contained in:
LukeMathWalker 2021-03-08 21:41:34 +00:00
parent f4b066b487
commit 310ffb01a5

View file

@ -1,4 +1,5 @@
use crate::domain::{NewSubscriber, SubscriberEmail, SubscriberName};
use crate::email_client::EmailClient;
use actix_web::{web, HttpResponse};
use chrono::Utc;
use sqlx::PgPool;
@ -23,7 +24,7 @@ impl TryInto<NewSubscriber> for FormData {
#[tracing::instrument(
name = "Adding a new subscriber",
skip(form, pool),
skip(form, pool, email_client),
fields(
email = %form.email,
name = %form.name
@ -32,6 +33,7 @@ impl TryInto<NewSubscriber> for FormData {
pub async fn subscribe(
form: web::Form<FormData>,
pool: web::Data<PgPool>,
email_client: web::Data<EmailClient>,
) -> Result<HttpResponse, HttpResponse> {
let new_subscriber = form
.0
@ -40,6 +42,15 @@ pub async fn subscribe(
insert_subscriber(&pool, &new_subscriber)
.await
.map_err(|_| HttpResponse::InternalServerError().finish())?;
// We are swallowing the error for the time being.
let _ = email_client
.send_email(
new_subscriber.email,
"Welcome!",
"Welcome to our newsletter!",
"Welcome to our newsletter!",
)
.await;
Ok(HttpResponse::Ok().finish())
}