Rust
Rust
Send HTML Email with Image Downloaded from URL
Demonstrates how to compose an HTML email with an embedded image where the image data is downloaded from a URL.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// First download the image we'll be adding to the HTML "img" tag.
let bd_jpg = chilkat::BinData::new();
let http = chilkat::Http::new();
if http.quick_get_bd("https://www.chilkatsoft.com/images/starfish.jpg", &bd_jpg).is_err() {
println!("{}", http.last_error_text());
return;
}
let mailman = chilkat::MailMan::new();
// Use your SMTP server..
mailman.set_smtp_host("smtp.yourserver.com");
mailman.set_smtp_port(587);
mailman.set_start_tls(true);
// Set the SMTP login/password
mailman.set_smtp_username("my_login");
mailman.set_smtp_password("my_password");
// Create an HTML email.
let email = chilkat::Email::new();
email.set_subject("HTML Email with Image");
email.set_from("Dave <somebody@mydomain.com>");
let _ = email.add_to("Chilkat", "info@chilkatsoft.com");
let html = "<html><body><p>This is an HTML email with an embedded image.</p><p><img src=\"starfish.jpg\" /></p></body></html>".to_string();
email.set_html_body(&html);
// Note: The "starfish.jpg" here must match the name in the "img" tag's "src" attribute in the HTML above.
if email.add_related_bd2(&bd_jpg, "starfish.jpg").is_err() {
println!("{}", email.last_error_text());
return;
}
let _ = email.save_eml("qa_output/out.eml");
// success = mailman.SendEmail(email);
// if (success == ckfalse) {
// println mailman.LastErrorText;
// return;
// }
//
// ignore = mailman.CloseSmtpConnection();
println!("Success.");