really need youre expertise on this one.
Been struggling for a few days now.
We get a picture provided by a local system which we want to send with using email with a inline attachment.
It all works if i copy the JPEG picture to my local computer and send it.
I’m using the crate lettre to send email
When i do this i see the picture in my email
let content_id = String::from("alertimage");
let filebody = std::fs::read("C:/Users/BerryJansen/repos/vaibs-alert-manager/src/images/alert.jpg")?;
let content_type = ContentType::parse("image/jpeg")?;
let attachment_image = Attachment::new_inline(content_id).body(filebody, content_type);
let html = String::from(format!(
r#"<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alert from system</title>
</head>
<body>
<div style="display: flex; flex-direction: column; align-items: left;">
<h4 style="font-family: Arial, Helvetica, sans-serif;">See picture</h4>
<p style="font-family: Arial, Helvetica, sans-serif;"><img src="cid:alertimage" alt="AlertImage"></p>
</div>
</body>
</html>"#
));
let message = Message::builder()
.from("Subject 1 <[email protected]>".parse()?)
.to("Subject 2 <[email protected]>".parse()?)
.subject(format!("Please notice : {}", alert.event_time_stamp))
.multipart(
MultiPart::mixed()
.singlepart(
SinglePart::builder()
.header(header::ContentType::TEXT_HTML)
.body(html),
)
.singlepart(attachment_image)
)?;
But when i use crate reqwest too GET the picture from the local storage
let client = reqwest::Client::builder().build()?;
let data = "";
let request = client
.request(reqwest::Method::GET, "http://192.168.20.220/ainvr/samba/image/2024/5/28/7/18/2/94d47b28-0b71-45c5-8797-cfd30e2f8d41.jpg")
.body(data);
let response = request.send().await?;
let body = response.text().await?;
And use this code also providing me a Vec
let content_id = String::from("alertimage");
let filebody = body.as_bytes().to_vec();
let content_type = ContentType::parse("image/jpeg")?;
let attachment_image = Attachment::new_inline(content_id).body(filebody, content_type);
While when i use a GET command using POSTMEN i do see the picture in the body response
What i’m I doing from?
I’ve tried to copy the bytes to a local file, path is generated by crate directories
let local_path = imagearchivepath("temp.jpg")?;
info!("Image saved at : {:?}", &local_path);
let mut file = std::fs::File::create(&local_path)?;
file.write_all(&body.as_bytes())?;
Another try with crate ‘image’
let img = ImageReader::new(Cursor::new(body.as_bytes())).with_guessed_format()?.decode()?;
img.save_with_format(&local_path, image::ImageFormat::Jpeg)?;
Also no result