1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
#[cfg(test)]
extern crate dotenv;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate reqwest;
pub use self::message::{EmailAddress, Message, Options};
pub use self::transmission::{Transmission, TransmissionResponse, TransmissionApiResult, TransmissionApiError};
mod message;
mod transmission;
#[cfg(test)]
mod tests {
use super::*;
fn get_api_key() -> String {
use std::env;
use dotenv::dotenv;
dotenv().ok();
let api_key = env::var("SPARKPOST_API_KEY").expect("SPARKPOST_API_KEY must be set");
api_key
}
#[ignore]
#[test]
fn send_email() {
let tm = Transmission::new(get_api_key(), "https://api.eu.sparkpost.com/api/v1/transmissions".into());
let mut email: Message =
Message::new(
EmailAddress::with_name(
"hello@email.letsorganise.app",
"noreply")
);
email.add_recipient("test@hgill.io".into())
.set_subject("Testing builder email sandbox")
.set_html("This is the html body of the email")
.set_text("This is the text body of the email");
let result = tm.send(&email);
match result {
Ok(res) => {
match res.results {
Some(result) => {
assert_eq!(1, result.total_accepted_recipients);
assert_eq!(0, result.total_rejected_recipients);
}
None => {
println!("res: \n {:#?}", &res);
}
}
}
Err(error) => {
println!("error \n {:#?}", error);
}
}
}
}