-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathformat_multipart.rs
55 lines (52 loc) · 2.29 KB
/
format_multipart.rs
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
extern crate emailmessage;
use emailmessage::{header, Message, MultiPart, SinglePart};
fn main() {
let m: Message<MultiPart<&str>> = Message::builder()
.from("NoBody <[email protected]>".parse().unwrap())
.reply_to("Yuin <[email protected]>".parse().unwrap())
.to("Hei <[email protected]>".parse().unwrap())
.subject("Happy new year")
.mime_body(
MultiPart::mixed()
.multipart(
MultiPart::alternative()
.singlepart(
SinglePart::quoted_printable()
.header(header::ContentType("text/plain; charset=utf8".parse().unwrap()))
.body("Привет, мир!")
)
.multipart(
MultiPart::related()
.singlepart(
SinglePart::eight_bit()
.header(header::ContentType("text/html; charset=utf8".parse().unwrap()))
.body("<p><b>Hello</b>, <i>world</i>! <img src=smile.png></p>")
)
.singlepart(
SinglePart::base64()
.header(header::ContentType("image/png".parse().unwrap()))
.header(header::ContentDisposition {
disposition: header::DispositionType::Inline,
parameters: vec![],
})
.body("<smile-raw-image-data>")
)
)
)
.singlepart(
SinglePart::seven_bit()
.header(header::ContentType("text/plain; charset=utf8".parse().unwrap()))
.header(header::ContentDisposition {
disposition: header::DispositionType::Attachment,
parameters: vec![
header::DispositionParam::Filename(
header::Charset::Ext("utf-8".into()),
None, "example.c".as_bytes().into()
)
]
})
.body("int main() { return 0; }")
)
);
println!("{}", m);
}