# letterman - rust
this is a grounds up smtp client and server lib for rust, trust-dns-resolver is used to resolve the mx records of the domains if no records are found smtp is tried on the given domain if not it fails. native-tls is used to support start tls smtp commands works with pretty much all email providers.
## domain setup
set spf, dkim and dmarc reocrds on your domain for verifiable email delivery and reception.
## Supported SMTP features/extensions
- RDNS Validation
- DKIM Validation
- SPF Lookup
- 8BITMIME
- Alternative Body
- Attachments
- Base64/Quoted-printable Decoding
### testing smtp server
you can test dkim validation, spf lookup and email body validation on dkimvalidator.com
***please support the creators of testing servers***
# Client Api
client api supports pipelinening and can send multiple smtp commands in batch for faster resolution, dkim is required for mail delivery.
```rust
use std::time::Instant;
use letterman::client::{read_key,Connection,Email};
#[tokio::main]
async fn main() {
println!(">>> sending mail async");
//this is private dkim key for which public key is published at a dkim subdomain as a txt record.
let key:String;
match read_key("../secret/private.key".to_string()).await{
Ok(v)=>{
key = v;
},
Err(e)=>{
println!("!!! {:?}",e);
return;
}
}
let mut conn:Connection;
match Connection::new(
String::from("localhost"), //receiver domain
String::from("mailcenter.herokuapp.com"), //server name
key, //dkim private key
String::from("dkim"), //dkim txt value name
String::from("silvergram.in"), //sender domain
){
Ok(v)=>{conn = v;},
Err(_)=>{
return;
}
}
//add emails to this connection
//emails are parsed before the connection si even started
//large number of emails in one connection will delay for parsing all emails
for i in 0..1{
conn.add(build_mail_new(i.to_string()));
}
let hold = Instant::now();
if true{
match conn.send().await{
Ok(_v)=>{
println!("send successfull : {:?} {:?}",_v.0,_v.1);
},
Err(_e)=>{
println!("send failed : {:?}",_e);
}
}
}
println!("finished in : {:?}",hold.elapsed());
}
fn build_mail_new(tracking_id:String) -> Email{
let mut email = Email::new();
email.server_name(String::from("mailcenter.herokuapp.com"));
email.name(String::from("gzbakku"));
email.from(String::from("akku@silvergram.in"));
email.tracking_id(tracking_id);
email.to(String::from("gzbakku@localhost"));
//the receivers will receive the message this feature allows cc and bcc smtp functions
email.receiver(String::from("gzbakku@localhost"));
email.receiver(String::from("gzbakku1@localhost"));
email.subject(String::from("hello world"));
email.body(String::from("first message\r\nsecond message\r\nthird message"));
//add html body
if 1 == 1 {
email.html(
String::from(
"