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

Examples Not Working #68

Closed
sezna opened this issue May 12, 2016 · 12 comments
Closed

Examples Not Working #68

sezna opened this issue May 12, 2016 · 12 comments

Comments

@sezna
Copy link

sezna commented May 12, 2016

I'm trying to use this crate in a project I'm working on, and I can't get the examples to compile. They cause panics.

My code (the example code):

use lettre::transport::smtp::{SmtpTransport, SmtpTransportBuilder};
use lettre::email::EmailBuilder;
use lettre::transport::EmailTransport;

let email = EmailBuilder::new()
                    .to("root@localhost")
                    .from("user@localhost")
                    .body("Hello World!")
                    .subject("Hello")
                    .build()
                    .unwrap();

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

assert!(result.is_ok());

The error:

thread '<main>' panicked at 'assertion failed: result.is_ok()', main.rs:26
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Process didn't exit successfully: `/path/to/code` (exit code: 101)
@sezna
Copy link
Author

sezna commented May 12, 2016

I can't seem to edit my post on my mobile browser but I made a typo. It is a runtime error, not a compile error.

@amousset
Copy link
Member

You should try to print the content of result, it will give you the reason of the failure.

@sezna
Copy link
Author

sezna commented May 13, 2016

Ok, I did that, and this is what it gave me:

an I/O error occurred

It may be something I'm doing incorrectly, and if so, sorry about that, but I can't seem to locate an error on my end. I'm not doing any I/O.

@amousset
Copy link
Member

You can try to display the error cause with error.cause(), it should give more details about the I/O error.

@amousset
Copy link
Member

You can also have a look at the logs of your local mail server to see where the failure happens.

@djc
Copy link
Contributor

djc commented May 22, 2016

I actually have similar problems. In my case, I get "an I/O error occurred", and the underlying failure is "connection refused". I'm using the same SmtpTransportBuilder as the reporter, and I verified with a Python script that using SMTP through localhost:25 is working fine there.

@djc
Copy link
Contributor

djc commented May 23, 2016

BTW, I can reproduce this with cargo test against current master or v0.5.1:

test transport_smtp::simple_sender ... FAILED

failures:

---- transport_smtp::simple_sender stdout ----
    thread 'transport_smtp::simple_sender' panicked at 'assertion failed: result.is_ok()', tests/transport_smtp.rs:18
stack backtrace:
   1:     0x5649b8e4cd50 - std::sys::backtrace::tracing::imp::write::h82353b94d9957b5a
   2:     0x5649b8e5092b - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hd08c9fd28a21a931
   3:     0x5649b8e5051c - std::panicking::default_hook::h9f5ce461fe95b992
   4:     0x5649b8e416b8 - std::panicking::rust_panic_with_hook::hfb9137c9fa89bbb0
   5:     0x5649b8d7c777 - std::panicking::begin_panic::h91a119e8e2811f21
                        at src/libstd/panicking.rs:328
   6:     0x5649b8d7a38b - lib::transport_smtp::simple_sender::hd483d90c8b7a0dbd
                        at /home/djc/src/lettre/<std macros>:3
   7:     0x5649b8db8c36 - _<F as std..boxed..FnBox<A>>::call_box::h8c9c9860460d767a
   8:     0x5649b8dbb367 - std::panicking::try::call::h5112e6c4747ac9f2
   9:     0x5649b8e5a12b - __rust_try
  10:     0x5649b8e5a0ce - __rust_maybe_catch_panic
  11:     0x5649b8dbb78e - _<F as std..boxed..FnBox<A>>::call_box::h7b2b6b6ac924dcb2
  12:     0x5649b8e4ef44 - std::sys::thread::Thread::new::thread_start::h99197ac7442ad7fa
  13:     0x7f9013b14493 - start_thread
  14:     0x7f90136425dc - __clone
  15:                0x0 - <unknown>


failures:
    transport_smtp::simple_sender

test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured

error: test failed

@amousset
Copy link
Member

Can you run your test with the latest version (I just added a new log) from master with RUST_LOG=debug ./program to get full logs?

Which mail server is running on this host? Could you try to connect with telnet on port 25 (telnet localhost 25), type EHLO localhost and give the result?

@djc
Copy link
Contributor

djc commented May 24, 2016

Aha! Here's the output from running sezna's test program against git master lettre:

djc@enrai rusttest $ RUST_LOG=debug ./target/debug/rusttest 
DEBUG:lettre::transport::smtp::client: connecting to [::1]:25
thread '<main>' panicked at 'assertion failed: result.is_ok()', src/main.rs:25
note: Run with `RUST_BACKTRACE=1` for a backtrace.

For some reason, Rust/lettre is resolving localhost to ::1. However, my Postfix (3.0.3) instance is only listening on IPv4. When I try gethostbyname('localhost') from Python, I get IPv4:

>>> import socket
>>> print socket.gethostbyname('localhost')
127.0.0.1
>>> sock = socket.socket()
>>> sock.connect(('localhost', 25))
>>> sock.send('EHLO localhost\n')
15
>>> print sock.recv(1024)
220 enrai.xavamedia.nl ESMTP Postfix
250-enrai.xavamedia.nl
250-PIPELINING
250-SIZE 26214400
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 SMTPUTF8

>>>

@amousset
Copy link
Member

Then you can use SmtpTransportBuilder::new("127.0.0.1:25") to connect to ipv4.

@djc
Copy link
Contributor

djc commented May 24, 2016

Sure, but why doesn't Rust/lettre resolve localhost the same as Python (as well as just ping)?

@amousset
Copy link
Member

I don't know, closing as it is not really related to lettre.

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

No branches or pull requests

3 participants