use crate::config::Config; use crate::rfd::Posts; use crate::rfd::Topic; use sendgrid::SGClient; use sendgrid::{Destination, Mail}; const RFD_FORUMS_BASE_URL: &str = "https://forums.redflagdeals.com"; pub fn send(topic: &Topic, posts: &Posts, expression: &str, config: &Config) { let api_key = &config.sendgrid.api_key; let sg = SGClient::new(api_key.to_string()); let web_path = format!("{}/{}", RFD_FORUMS_BASE_URL, topic.web_path); let html_message = format!( "\ Date: {}

Dealer: {}

Deal: {}

Post: {}\

Body: {}

Matched by expression: {} ", topic.post_time, topic.offer.dealer_name.as_ref().unwrap_or(&"".to_string()), topic.offer.url.as_ref().unwrap_or(&"".to_string()), web_path, posts.posts[0].body, expression, ); debug!("{}", html_message); let mail_info = Mail::new() .add_to(Destination { address: &config.sendgrid.mail_to, name: "you", }) .add_from(&config.sendgrid.mail_from) .add_subject(&topic.title) .add_html(&html_message); debug!("Sending email notification."); match sg.send(mail_info) { Err(err) => println!("SendGrid failed to send mail. Error: {err}"), Ok(body) => println!("SendGrid Response: {body:?}"), }; }