Skip to content

Commit

Permalink
all working fine
Browse files Browse the repository at this point in the history
  • Loading branch information
vrn21 committed Aug 11, 2024
1 parent a77a8b5 commit 5953c2b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
38 changes: 24 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use utils::recepients::{self, mail_list_from_csv};

mod utils;
#[tokio::main]
async fn main() {
Expand All @@ -21,18 +23,26 @@ async fn main() {
.port(587)
.build();

utils::mail::send_email_smtp(
&mailer,
from.as_str(),
utils::recepients::mail_list().as_str(),
utils::mail_content::subject().as_str(),
utils::mail_content::mail_content(),
)
.await
.unwrap();

println!(
"Successfully sent email(s) to {}",
utils::recepients::mail_list()
);
let maillist = mail_list_from_csv();

for recepient in maillist.iter() {
println!(
"Sending mail to name:{}, mailid:{}, team: {}",
recepient.name, recepient.mailid, recepient.team
);
utils::mail::send_email_smtp(
&mailer,
from.as_str(),
&recepient.mailid,
utils::mail_content::subject().as_str(),
utils::mail_content::mail_content(recepient),
)
.await
.unwrap();
}

// println!(
// "Successfully sent email(s) to {}",
// utils::recepients::mail_list()
// );
}
19 changes: 11 additions & 8 deletions src/utils/mail_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ pub fn subject() -> String {
"Sending email with Rust".to_string()
}

pub fn mail_content(receiver: Receiver) -> String {
r#"<body>
pub fn mail_content(receiver: &Receiver) -> String {
format!(
r#"<body>
<div style="font-family: Arial, Helvetica, sans-serif; padding: 10px; background-color: #002147; display: flex; align-items: center; justify-content: center; min-height: 100vh;">
<div style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #ffffff; border-radius: 10px; line-height: 1.6; border: 1px solid #c7c3c3;">
<div style="text-align: center;">
Expand All @@ -78,15 +79,15 @@ pub fn mail_content(receiver: Receiver) -> String {
<div style="text-align: center; margin-top: 20px;">
<h3>You've been shortlisted for the next round</h3>
</div>
<p>Dear _,</p>
<p>Dear {},</p>
<p><strong>Congratulations!</strong> We are pleased to inform you that you have been shortlisted for the next round of selection for the <strong>[] team</strong> of FOSS MEC 2024. Your passion and skills have impressed us, and we are excited to see how you can contribute further.</p>
<p><strong>Congratulations!</strong> We are pleased to inform you that you have been shortlisted for the next round of selection for the <strong>{} team</strong> of FOSS MEC 2024. Your passion and skills have impressed us, and we are excited to see how you can contribute further.</p>
<p>To ensure you stay connected with the team and up-to-date with all our plans, we've created a WhatsApp group where we'll be coordinating our efforts and sharing important information. This will be our primary platform for communication, so we encourage you to join the group as soon as possible.</p>
<p>Please join the WhatsApp group to stay informed about our upcoming meetings and discussions. We'll be sharing important updates and details there!</p>
<div style="text-align: left; margin: 20px 0;">
<a href="https://www.example.com/join-group" style="text-decoration: none;">
<a href={} style="text-decoration: none;">
<button style="background-color: #F5A212; border: none; color: white; padding: 13px 15px; text-align: center; font-size: 0.8em; cursor: pointer; border-radius: 6px;">
<strong>Join the group</strong>
</button>
Expand All @@ -102,7 +103,9 @@ pub fn mail_content(receiver: Receiver) -> String {
</p>
</div>
</div>
</body>
"#.to_string()
</body>"#,
receiver.name,
receiver.team,
receiver.get_grp_link()
)
}
21 changes: 6 additions & 15 deletions src/utils/recepients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,19 @@ use std::{fs::File, io::BufReader};

use crate::utils::mail_content::Receiver;

pub fn mail_list_from_csv(filename: String) -> Vec<String> {
pub fn mail_list_from_csv() -> Vec<Receiver> {
//input csv from arg
//read data then store to vec<Receiver>
// return this data from this fn
let mut rdr = csv::Reader::from_reader(BufReader::new(File::open("./data.csv").unwrap()));
let mut vec: Vec<Receiver> = vec![];
let mut rdr = csv::Reader::from_reader(BufReader::new(File::open("./Recepients.csv").unwrap()));
for result in rdr.deserialize() {
// Notice that we need to provide a type hint for automatic
// deserialization.
let record: Receiver = result.unwrap();
//append to vector
// println!("email is:{:?}", record.email);
// println!("name is:{:?}", record.name);
// match record.team {
// Team::Tech => {
// println!("yes team is tech");
// }
// _ => {
// println!("team is not tech");
// }
// }
let mut record: Receiver = result.unwrap();
vec.push(record);
}
vec![]
vec
}

pub fn mail_list_test() -> String {
Expand Down

0 comments on commit 5953c2b

Please sign in to comment.