Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send gets stuck when the message has a binary attachment #7

Closed
arturoc opened this issue Aug 16, 2022 · 10 comments
Closed

Send gets stuck when the message has a binary attachment #7

arturoc opened this issue Aug 16, 2022 · 10 comments

Comments

@arturoc
Copy link

arturoc commented Aug 16, 2022

Adding a binary attachment makes the sent command get stuck and never finish until the server ends the connection. Sending a text attachment works fine. The binary attachment is only 98Kb.

@mdecimus
Copy link
Member

In order to reproduce the problem, could you provide the code you're using and if possible also the binary attachment?

@mdecimus
Copy link
Member

Closing as no reply was received in 14 days.

@mdecimus mdecimus closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2022
@jacg
Copy link

jacg commented Sep 18, 2022

I've run into a problem that sounds similar to this one.

Here is some code which might help you reproduce it. I have replaced all the addresses, servers and credentials that I used in my test, with todo!()s.

The value of snip is crucial: with its current value (or greater) the message send hangs. For any smaller value of snip the message gets sent successfully without delay. Changing the length of the addresses used, changes the value of snip that crosses the threshold between success and failure, so it looks like it depends on total message size.

Every PDF I tried (whose size exceeds snip) caused this failure. Including ones I have managed to send successfully using the server I used in my tests (with manual MUAs).

use mail_send::{mail_builder::MessageBuilder, Transport};

#[tokio::main]
async fn main() {

    let snip = 55663;

    let sender_name = todo!();
    let sender_address = todo!();
    let smtp_server = todo!();
    let username = todo!();
    let pw = todo!();

    let recipient_name = todo!();
    let recipient_address = todo!();

    let pdf_attachment = include_bytes!("../../sample.pdf").as_ref();
    let pdf_attachment = &pdf_attachment[..snip];
    let message = format!("PDF attachment length: {}", pdf_attachment.len());
    println!("{message}");

    let message = MessageBuilder::new()
        .from((sender_name, sender_address))
        .to(vec![
            (recipient_name, recipient_address),
        ])
        .subject(&message)
        .text_body(&message)
        .binary_attachment("application/pdf", "attachment.pdf", pdf_attachment);

    Transport::new(smtp_server)
        .credentials(username, pw)
        .allow_invalid_certs(true)
        .connect_tls()
        .await
        .unwrap()
        .send(message)
        .await
        .unwrap();
}

@mdecimus
Copy link
Member

Hi @jacg ,

I was able to reproduce the problem with your code snippet. The buffer was not being properly flushed, that is why it was getting stuck.
I just pushed a fix for this bug to the main branch, can you confirm that it works for you as well?

Thanks.

@jacg
Copy link

jacg commented Sep 20, 2022

I can confirm that it no longer blocks. But (after removing all the snipping) the PDF document arrives 'damaged' at the other end, and I cannot open it with any of the PDF viewers I tried.

@jacg
Copy link

jacg commented Sep 20, 2022

The document I'm using to test is 95k, but the one that is received is 130k. I'll try to come up with some more precise information when I have more time. Would you like me to file a separate issue for this, or continue here?

@mdecimus
Copy link
Member

It may be related to the same problem. I'm looking into this now and will send you an update soon.

@mdecimus
Copy link
Member

Done, it should work now.

@jacg
Copy link

jacg commented Sep 20, 2022

It seems to work correctly for me now.

Many thanks for the quick solution!

@mdecimus
Copy link
Member

Great! Version 0.2.3 has been pushed to crates.io with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants