Rust
Rust
Create Email with Non-Standard Binary Body
Creates an email where the only body is a binary WAV file. The technique used in the example could be applied to other binary files, such as PDF, MS-WORD docs, Excel docs, etc.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let mime = chilkat::Mime::new();
if mime.set_body_from_file("VoiceMessage.wav").is_err() {
println!("{}", mime.last_error_text());
return;
}
// The MIME has this header:
// Content-Disposition: attachment;
// filename="VoiceMessage.wav"
// Content-Transfer-Encoding: base64
// Content-Type: audio/x-wav;
// name="VoiceMessage.wav"
// We don't want the content-disposition to be an
// attachment -- otherwise the email object will self-correct
// and put it in a multipart/mixed format...
mime.set_disposition("");
mime.set_filename("");
let str_mime = mime.get_mime().unwrap_or_default();
println!("{}", str_mime);
// Now load it into an email object:
let email = chilkat::Email::new();
if email.set_from_mime_text(&str_mime).is_err() {
println!("{}", email.last_error_text());
return;
}
// Add subject, TO, FROM, etc.
email.set_subject("This is a test");
email.set_from("support@chilkatsoft.com");
let _ = email.add_to("Matt", "matt@chilkatsoft.com").is_ok();
// Your email is ready to send.
// (but for this example, we'll simply save it to a file...)
if email.save_eml("email.eml").is_err() {
println!("{}", email.last_error_text());
return;
}
println!("OK!");