Skip to content

Flexible timeouts for larger emails #1755

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

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ smallvec = "1.0.0"
surf = { version = "2.0.0-alpha.4", default-features = false, features = ["h1-client"] }
num-derive = "0.3.0"
num-traits = "0.2.6"
async-smtp = { version = "0.3" }
async-smtp = { git = "https://github.com/async-email/async-smtp", branch = "smtptimeout" }
email = { git = "https://github.com/deltachat/rust-email", branch = "master" }
lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" }
async-imap = "0.3.1"
Expand Down
12 changes: 9 additions & 3 deletions src/smtp/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use async_smtp::*;

use crate::context::Context;
use crate::events::Event;
use std::time::Duration;

pub type Result<T> = std::result::Result<T, Error>;

Expand All @@ -30,7 +31,7 @@ impl Smtp {
message: Vec<u8>,
job_id: u32,
) -> Result<()> {
let message_len = message.len();
let message_len_bytes = message.len();

let recipients_display = recipients
.iter()
Expand All @@ -47,11 +48,16 @@ impl Smtp {
);

if let Some(ref mut transport) = self.transport {
transport.send(mail).await.map_err(Error::SendError)?;
// The timeout is 1min + 3min per MB.
let timeout = 60 + (180 * message_len_bytes / 1_000_000) as u64;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I proposed is to just set it to 600 seconds. Maybe actually it is not such a good idea, because there is a chance to get stuck for 10 minutes while sending a small message.

transport
.send_with_timeout(mail, Some(&Duration::from_secs(timeout)))
.await
.map_err(Error::SendError)?;

context.emit_event(Event::SmtpMessageSent(format!(
"Message len={} was smtp-sent to {}",
message_len, recipients_display
message_len_bytes, recipients_display
)));
self.last_success = Some(std::time::SystemTime::now());

Expand Down