Reject email addresses that known to be undeliverable during signup. Some users signup with invalid email addresses, which causes the welcome email (which contains the email confirmation link) to bounce. Too many bounces hurt our ability to send mail. We check that an email address is undeliverable by checking if the domain has a mail server and if the server returns an invalid address error when attempting to send mail. This isn't foolproof since some servers don't return an error if the address doesn't exist. If the checks fail we know the address is bad, but if the checks pass that doesn't guarantee the address is good. However, this is still good enough to filter out bad addresses for popular providers like Gmail and Microsoft that do return nonexistent address errors. The address existence check requires being able to connect to mail servers over port 25. This may fail if your network blocks port 25, which many home ISPs and hosting providers do by default.
24 lines
1020 B
Ruby
24 lines
1020 B
Ruby
require 'test_helper'
|
|
|
|
class EmailValidatorTest < ActiveSupport::TestCase
|
|
context "EmailValidator" do
|
|
context "#undeliverable?" do
|
|
should "return good addresses as deliverable" do
|
|
assert_equal(false, EmailValidator.undeliverable?("webmaster@danbooru.donmai.us"))
|
|
assert_equal(false, EmailValidator.undeliverable?("noizave+spam@gmail.com"))
|
|
end
|
|
|
|
should "return nonexistent domains as undeliverable" do
|
|
assert_equal(true, EmailValidator.undeliverable?("nobody@does.not.exist.donmai.us"))
|
|
end
|
|
|
|
# XXX these tests are known to fail if your network blocks port 25.
|
|
should_eventually "return nonexistent addresses as undeliverable" do
|
|
assert_equal(true, EmailValidator.undeliverable?("does.not.exist.13yoigo34iy@gmail.com"))
|
|
assert_equal(true, EmailValidator.undeliverable?("does.not.exist.13yoigo34iy@outlook.com"))
|
|
assert_equal(true, EmailValidator.undeliverable?("does.not.exist.13yoigo34iy@hotmail.com"))
|
|
end
|
|
end
|
|
end
|
|
end
|