gen-smtp / gen_smtp

The extensible Erlang SMTP client and server library.
Other
682 stars 265 forks source link

The Example doesn't work well #40

Closed barcoyou closed 11 years ago

barcoyou commented 11 years ago

I exactly follow the example in README, although the program runs properly nothing happen to me and I didn't receive any mail in my Gmail box.

Erlang R16B01 (erts-5.10.2) [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false] [dtrace]

Eshell V5.10.2 (abort with ^G) 1> gen_smtp_server:start(smtp_server_example).

=INFO REPORT==== 24-Jul-2013::11:01:18 === gen_smtp_server starting at nonode@nohost {ok,<0.34.0>}

=INFO REPORT==== 24-Jul-2013::11:01:18 === gen_smtp_server listening on {0,0,0,0}:2525 via tcp 2> gen_smtp_client:send({"barcojie@gmail.com", ["barcojie@gmail.com"], "Subject: testing\r\nFrom: Andrew Thompson \r\nTo: Some Dude \r\n\r\nThis is the email body"},[{relay, "localhost"}, {port, 2525}]). {ok,<0.38.0>} peer: {127,0,0,1} EHLO from creatii.co Mail from barcojie@gmail.com Mail to barcojie@gmail.com message from barcojie@gmail.com to [<"barcojie@gmail.com">] queued as 5fb787e1a9ed86dff33c02d34050ce12, body length 82 3>

mworrell commented 11 years ago

In the example you just sent an e-mail to your local machine, not Google. gen_smtp e-mail server doesn't relay messages (to gmail in this instance).

barcoyou commented 11 years ago

Thank you for replying. Then how can I send a mail to my Gmail box?

mworrell commented 11 years ago

Like you did in the gen_smtp_client example, except without relay and port options.

You will need a relay if you have an ISP that blocks access to port 25 on other servers than their own smtp server. (ziggo.nl is an example of such an ISP). In that case the relay is the smtp server of your ISP.

barcoyou commented 11 years ago

So actually I don't need to start gen_smtp_server?

mworrell commented 11 years ago

Indeed - the gen_smtp_server is to receive e-mail. The gen_smtp_client is to send e-mail.

barcoyou commented 11 years ago

To receive email how can I setup an email account with gen_smtp_server at my local server?

Vagabond commented 11 years ago

gen_smtp is NOT a complete mailserver, it provides an implementation of the SMTP protocol and hooks you can use to implement the actual server (email storage, queueing, relaying, etc). It is more of a library than an application.

barcoyou commented 11 years ago

Thank you very much for your elucidation.

barcoyou commented 11 years ago

Still nothing happen by just using gen_smtp_client to send mail, as following.

Erlang R16B01 (erts-5.10.2) [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false] [dtrace]

Eshell V5.10.2 (abort with ^G) 1> gen_smtp_client:send({"barcojie@gamil.com",["barcojie@gmail.com"],"Subject: testing\r\nFrom: Andrew Thompson \r\nTo: Some Dude \r\n\r\nThis is the email body"},[{relay, "smtp.gmail.com"},{port,465},{username, "barcojie@gmail.com"},{password, "mypass"}]). {ok,<0.36.0>} 2>

barcoyou commented 11 years ago

Could anyone help me figure out where the problem lies in?

Vagabond commented 11 years ago

I just tested and I was able to send email to another account fine via gmail.

barcoyou commented 11 years ago

Using port 25 I got error: exception error: {error,retries_exceeded, {network_failure,"smtp.gmail.com",{error,closed}}}

Vagabond commented 11 years ago

Does your ISP block port 25?

mworrell commented 11 years ago

First: try to use a better (valid) message body - to prevent the spam filters trapping your e-mail. Or test the body with another library (php/ command-line/ etc) to see if it arrives. Currently I am not sure what we are testing :)

I see that you try to relay using the gmail smtp server.

I just tested with the following, and I received the message:

Email = {
    "marc@maximonster.com",
    ["marc@maximonster.com"],
    <<"From: MW <marc@maximonster.com>\r\nTo: MW <marc@maximonster.com>\r\nSubject: Test\r\n\r\nDit is een test.">>
},
Options = [
    {ssl,true},
    {no_mx_lookups,true},
    {relay,"smtp.gmail.com"},
    {username,"marc@maximonster.com"},
    {password,"xxxx"},
    {auth,always}
],
gen_smtp_client:send_blocking(Email, Options).

(BTW in your example above you sent the message from "barcojie@gamil.com" -- I assume that is a typo in this ticket?)

barcoyou commented 11 years ago

With this Options, it works now. Thank you!

mworrell commented 11 years ago

Good to hear that it works, thanks for reporting back.