Error using Async Feature of Lettre after compilation

The code compile whitout problems but later i get:
thread 'main' panicked at 'InnerAsyncNetworkStream::None must never be built', lettre/src/transport/smtp/client/async_net.rs:500:17
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

use lettre::{Message,AsyncSmtpTransport, AsyncStd1Connector,
             AsyncStd1Transport,Transport};
use std::fs::{File, OpenOptions};
use std::io::{self, BufRead, Write, BufReader, Lines};
use regex::Regex;
use async_trait::async_trait;
use async_std::io::Error;

struct Datos{

    from: String,
    reply_to: String,
    to: String,
    subjetc: String,
    body: String,
    user: String,
    pass: String,
    server: String,

}
#[async_trait]

trait Send{
 async   fn send(self: &Self);
}

#[async_trait]
impl Send for Datos {
   async  fn send(self: &Self) {

             let email_regex = Regex::new(r"^([a-z0-9_+]([a-z0-9_+.]*[a-z0-9_+])?)@([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6})").unwrap();

             if email_regex.is_match(&self.from) {
                 let email = match Message::builder()
                     .from(self.from.parse().unwrap())
                     .reply_to(self.reply_to.parse().unwrap())
                     .to(self.to.parse().unwrap())
                     .subject(&self.subjetc)
                     .body(String::from(&self.body)) {
                     Ok(email) => email,
                     Err(err) => {
                         eprintln!("An error ocurred when create email {}: {:?}", self.from, err);
                         return;
                     }
                 };

                 let creds = Credentials::new(self.user.to_string(), self.pass.to_string());

// Open a remote connection to gmail
                 let mailer = AsyncSmtpTransport::<AsyncStd1Connector>::starttls_relay(&self.server)
                     .unwrap()
                     .credentials(creds)
                     .build();

// Send the emai
                 match mailer.send(email).await{
                     Ok(_) => println!("Email sent successfully!"),
                     Err(e) => eprintln!("Could not send email: {:?}", e),
                 };
             } else { println!("Error to create an email"); }

     }
}

struct Read{
    file_read: String,
}

trait ReadLines{
    fn read_lines(self: &Self)-> io::Result<io::Lines<io::BufReader<File>>>;
}

impl ReadLines for Read{
    fn read_lines(self: &Self)-> io::Result<io::Lines<io::BufReader<File>>>{
        let file = File::open(&self.file_read)?;
        Ok(io::BufReader::new(file).lines())

    }

}
#[async_std::main]
 async fn main() {
    let archivo = Read {
        file_read: "archivo.txt".parse().unwrap(),
    };
    if let Ok(result) = Read::read_lines(&archivo) {
        for line in result {
            let line = line.unwrap();
            let split: Vec<&str> = line.split(":").collect();
            let enviar = Datos {
                from: split[1].to_string(),
                reply_to: split[1].to_string(),
                to: "some@hotmail.com".to_string(),
                subjetc: "Esto es una prueba".to_string(),
                server: split[0].parse().unwrap(),
                user: split[1].to_string(),
                body: "Esto es una prueba".to_string(),
                pass: split[2].to_string()
            };

            Send::send(&enviar).await
        }
    }
}

I have no prior knowledge about the lettre crate, but this looks like it could be a bug in lettre. Judging by the unhelpful error message and the fact that it stems from a debug_assert as opposed to an assert. Also looks like you’re using an 0.10.0.alpha._ version so one wouldn’t necessarily expect the crate to be 100% bug free yet on that version. (Still a good idea to report such a bug/issue, of course, after all it is a released version, probably meant for trying it out.)

Also I think you should mention when you post the same question at two different places in the internet as to avoid potential duplicate effort on people writing answers.

https://github.com/lettre/lettre/discussions/554

1 Like

I continue whit github and for now don't exist a solution. Thanks

Update some one can help ?

thread 'main' panicked at 'InnerAsyncNetworkStream::None must never be built', lettre/src/transport/smtp/client/async_net.rs:500:17
stack backtrace:
   0: std::panicking::begin_panic
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:521:12
   1: <lettre::transport::smtp::client::async_net::AsyncNetworkStream as futures_io::if_std::AsyncWrite>::poll_write
             at ./lettre/src/transport/smtp/client/async_net.rs:500:17
   2: <&mut T as futures_io::if_std::AsyncWrite>::poll_write
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-io-0.3.12/src/lib.rs:404:17
   3: <futures_util::io::write_all::WriteAll<W> as core::future::future::Future>::poll
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.12/src/io/write_all.rs:31:28
   4: lettre::transport::smtp::client::async_connection::AsyncSmtpConnection::write::{{closure}}
             at ./lettre/src/transport/smtp/client/async_connection.rs:261:9
   5: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
   6: lettre::transport::smtp::client::async_connection::AsyncSmtpConnection::command::{{closure}}
             at ./lettre/src/transport/smtp/client/async_connection.rs:255:9
   7: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
   8: lettre::transport::smtp::client::async_connection::AsyncSmtpConnection::abort::{{closure}}
             at ./lettre/src/transport/smtp/client/async_connection.rs:185:21
   9: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  10: lettre::transport::smtp::client::async_connection::AsyncSmtpConnection::starttls::{{closure}}
             at ./lettre/src/transport/smtp/client/async_connection.rs:156:13
  11: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  12: <lettre::transport::smtp::async_transport::AsyncStd1Connector as lettre::transport::smtp::async_transport::AsyncSmtpConnector>::connect::__connect::{{closure}}
             at ./lettre/src/transport/smtp/async_transport.rs:408:17
  13: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  14: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/future.rs:119:9
  15: lettre::transport::smtp::async_transport::AsyncSmtpClient<C>::connection::{{closure}}
             at ./lettre/src/transport/smtp/async_transport.rs:248:24
  16: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  17: <lettre::transport::smtp::async_transport::AsyncSmtpTransport<lettre::transport::smtp::async_transport::AsyncStd1Connector> as lettre::AsyncStd1Transport>::send_raw::__send_raw::{{closure}}
             at ./lettre/src/transport/smtp/async_transport.rs:68:24
  18: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  19: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/future.rs:119:9
  20: lettre::AsyncStd1Transport::send::__send::{{closure}}
             at ./lettre/src/lib.rs:117:9
  21: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  22: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/future.rs:119:9
  23: <smtp_checker_lettre::Datos as smtp_checker_lettre::Send>::send::__send::{{closure}}::{{closure}}
             at ./src/main.rs:76:24
  24: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  25: <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:199:17
  26: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/task_locals_wrapper.rs:60:13
  27: std::thread::local::LocalKey<T>::try_with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:272:16
  28: std::thread::local::LocalKey<T>::with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:248:9
  29: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/task_locals_wrapper.rs:55:9
  30: <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:197:13
  31: futures_lite::future::block_on::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.11.3/src/future.rs:89:27
  32: std::thread::local::LocalKey<T>::try_with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:272:16
  33: std::thread::local::LocalKey<T>::with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:248:9
  34: futures_lite::future::block_on
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.11.3/src/future.rs:79:5
  35: async_std::task::builder::Builder::blocking::{{closure}}::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:173:25
  36: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/task_locals_wrapper.rs:60:13
  37: std::thread::local::LocalKey<T>::try_with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:272:16
  38: std::thread::local::LocalKey<T>::with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:248:9
  39: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/task_locals_wrapper.rs:55:9
  40: async_std::task::builder::Builder::blocking::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:168:17
  41: std::thread::local::LocalKey<T>::try_with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:272:16
  42: std::thread::local::LocalKey<T>::with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:248:9
  43: async_std::task::builder::Builder::blocking
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:161:9
  44: async_std::task::block_on::block_on
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/block_on.rs:33:5
  45: <smtp_checker_lettre::Datos as smtp_checker_lettre::Send>::send::__send::{{closure}}
             at ./src/main.rs:69:18
  46: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  47: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/future.rs:119:9
  48: smtp_checker_lettre::main::main::{{closure}}
             at ./src/main.rs:132:13
  49: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  50: smtp_checker_lettre::main::{{closure}}
             at ./src/main.rs:103:1
  51: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  52: <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:199:17
  53: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/task_locals_wrapper.rs:60:13
  54: std::thread::local::LocalKey<T>::try_with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:272:16
  55: std::thread::local::LocalKey<T>::with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:248:9
  56: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/task_locals_wrapper.rs:55:9
  57: <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:197:13
  58: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.11.3/src/future.rs:526:33
  59: async_executor::Executor::run::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.4.0/src/lib.rs:236:9
  60: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  61: async_executor::LocalExecutor::run::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.4.0/src/lib.rs:437:9
  62: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:80:19
  63: async_io::driver::block_on
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-io-1.3.1/src/driver.rs:142:33
  64: async_global_executor::reactor::block_on::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.0.2/src/reactor.rs:3:18
  65: async_global_executor::reactor::block_on
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.0.2/src/reactor.rs:12:5
  66: async_global_executor::executor::block_on::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.0.2/src/executor.rs:26:36
  67: std::thread::local::LocalKey<T>::try_with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:272:16
  68: std::thread::local::LocalKey<T>::with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:248:9
  69: async_global_executor::executor::block_on
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.0.2/src/executor.rs:26:5
  70: async_std::task::builder::Builder::blocking::{{closure}}::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:171:25
  71: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/task_locals_wrapper.rs:60:13
  72: std::thread::local::LocalKey<T>::try_with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:272:16
  73: std::thread::local::LocalKey<T>::with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:248:9
  74: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/task_locals_wrapper.rs:55:9
  75: async_std::task::builder::Builder::blocking::{{closure}}
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:168:17
  76: std::thread::local::LocalKey<T>::try_with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:272:16
  77: std::thread::local::LocalKey<T>::with
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:248:9
  78: async_std::task::builder::Builder::blocking
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/builder.rs:161:9
  79: async_std::task::block_on::block_on
             at /Users/her0mx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.9.0/src/task/block_on.rs:33:5
  80: smtp_checker_lettre::main
             at ./src/main.rs:103:1
  81: core::ops::function::FnOnce::call_once
             at /Users/her0mx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Process finished with exit code 101

All I can say is that it looks like a bug in lettre.

1 Like

it is, i posted it in github and nobody can help, for this reason, i do tests and determine the program never open any async conection in the transport.

This a POC of the example in Github whit 20 email sending, only open 1 connection

use async_std::task;
use lettre::transport::smtp::authentication::Credentials;
use lettre::transport::smtp::AsyncSmtpTransport;
use lettre::{AsyncStd1Connector, AsyncStd1Transport, Message};
use std::io;
use std::time::Duration;

#[async_std::main]
async fn main() {
    let email = Message::builder()
        .from("Test <logistica.gp@naercris.com.mx>".parse().unwrap())
        .to("Paolo Barbolini <biccl@hotmail.com>".parse().unwrap())
        .subject("Testing")
        .body(String::from("Testing"))
        .unwrap();

    let creds = Credentials::new(
        "user".to_string(),
        "pass".to_string(),
    );

    let mailer = AsyncSmtpTransport::<AsyncStd1Connector>::starttls_relay("mail.somesmtp.com")
        .unwrap()
        .credentials(creds)
        .build();

    for _ in 0..20 {
        match mailer.send(email.clone()).await {
            Ok(_) => println!("Email sent successfully!"),
            Err(e) => eprintln!("Could not send email: {:?}", e),
        }
        task::sleep(Duration::from_secs(1)).await;
    }
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.