Error using Lettre Crate

I wanted to end email, for this purpose, I use the crate and tested it with the sample code provided with the lettre crate documentation. The code is:

[dependencies]
lettre = "0.9"
lettre_email = "0.9"

extern crate lettre;
extern crate lettre_email;

use lettre::{EmailTransport, SmtpTransport};
use lettre_email::EmailBuilder;
use std::path::Path;

fn main() {
    let email = EmailBuilder::new()
        // Addresses can be specified by the tuple (email, alias)
        .to(("user@example.org", "Firstname Lastname"))
        // ... or by an address only
        .from("user@example.com")
        .subject("Hi, Hello world")
        .text("Hello world.")
        .build()
        .unwrap();

    // Open a local connection on port 25
    let mut mailer = SmtpTransport::builder_unencrypted_localhost().unwrap()
                                                                   .build();
    // Send the email
    let result = mailer.send(&email);

    if result.is_ok() {
        println!("Email sent");
    } else {
        println!("Could not send email: {:?}", result);
    }

    assert!(result.is_ok());
}

When I try to  build/ run the project, It gives following error:

Compiling sendMail v0.1.0 (/home/syed/IdeaProjects/sendMail)
error[E0432]: unresolved import `file`
 --> src/main.rs:4:9
  |
4 | pub use file::FileTransport;
  |         ^^^^ help: a similar path exists: `lettre::file`

error[E0433]: failed to resolve: use of undeclared type or module `smtp`
 --> src/main.rs:6:9
  |
6 | pub use smtp::client::net::ClientTlsParameters;
  |         ^^^^ use of undeclared type or module `smtp`

error[E0432]: unresolved import `file`
 --> src/main.rs:4:9
  |
4 | pub use file::FileTransport;
  |         ^^^^ help: a similar path exists: `lettre::file`

error[E0433]: failed to resolve: use of undeclared type or module `smtp`
 --> src/main.rs:6:9
  |
6 | pub use smtp::client::net::ClientTlsParameters;
  |         ^^^^ use of undeclared type or module `smtp`

error[E0432]: unresolved import `sendmail`
error[E0432]: unresolved import `sendmail`
 --> src/main.rs:5:9
  |
5 | pub use sendmail::SendmailTransport;
  |         ^^^^^^^^ help: a similar path exists: `lettre::sendmail`

 --> src/main.rs:5:9
  |
5 | pub use sendmail::SendmailTransport;
  |         ^^^^^^^^ help: a similar path exists: `lettre::sendmail`

error[E0432]: unresolved import `smtp`
 --> src/main.rs:7:9
  |
7 | pub use smtp::ClientSecurity;
  |         ^^^^ help: a similar path exists: `lettre::smtp`

error[E0432]: unresolved import `smtp`
 --> src/main.rs:7:9
  |
7 | pub use smtp::ClientSecurity;
  |         ^^^^ help: a similar path exists: `lettre::smtp`

error[E0432]: unresolved import `smtp`
 --> src/main.rs:8:9
  |
8 | pub use smtp::SmtpClient;
  |         ^^^^ help: a similar path exists: `lettre::smtp`

error[E0432]: unresolved import `smtp`
 --> src/main.rs:9:9
  |
9 | pub use smtp::SmtpTransport;
  |         ^^^^ help: a similar path exists: `lettre::smtp`

error[E0432]: unresolved import `lettre::EmailTransport`
  --> src/main.rs:11:14
   |
11 | use lettre::{EmailTransport, SmtpTransport};
   |              ^^^^^^^^^^^^^^
   |              |
   |              no `EmailTransport` in the root
   |              help: a similar name exists in the module: `SmtpTransport`

error[E0432]: unresolved import `smtp`
 --> src/main.rs:8:9
  |
8 | pub use smtp::SmtpClient;
  |         ^^^^ help: a similar path exists: `lettre::smtp`

error[E0432]: unresolved import `smtp`
 --> src/main.rs:9:9
  |
9 | pub use smtp::SmtpTransport;
  |         ^^^^ help: a similar path exists: `lettre::smtp`

error[E0432]: unresolved import `lettre::EmailTransport`
  --> src/main.rs:11:14
   |
11 | use lettre::{EmailTransport, SmtpTransport};
   |              ^^^^^^^^^^^^^^
   |              |
   |              no `EmailTransport` in the root
   |              help: a similar name exists in the module: `SendmailTransport`

warning: unused import: `EmailTransport`
  --> src/main.rs:11:14
   |


Not sure which documentation you pulled that code from. But the code on the github page seems to be up to date

https://github.com/lettre/lettre

Thanks drewkett, I was reffering to the documentation available on crates.io. Let me check the latest documentation available.

Thanks, It worked. I have now two additional issues/requirments. FIrst I wanted to send File attachment and secondly I wanted to get rid of gmail less security warnings

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.