开发者

How check if an email exist without send in Ruby? Use of email_veracity_checker

I'm trying to create a ruby script that checks the real existence of some e-mail. I've found email_veracity_checker but I don't understand how implement a simple test. The "Readme" file only says the following:

# Add following entry in your config/environment.rb
config.gem 'email_veracity_checker', :lib => "email_check"

How to use:

#first param is user email address
#second sender address
#third param is domain address

#Note: It's not sending email, at the end point they quit connection.
EmailCheck.run("kiran@joshsoftware.com","no-reply@joshsoftware.com","joshsoftware.com").valid?

It's re开发者_JAVA技巧turn can be true or false"

Can someone help me? Thanks


What have you tried? It looks pretty simple. What it does is setting up an SMTP-connection, just like you do when you send a mail. At a certain point, in an SMTP-connection, your server says something like this:

I'ld like to send a mail to ...@....com

Most of the servers will return an error when this address doesn't exist. After this, a normal SMTP-connection would be free to send the actual message body. This class, however, closes the connection at this point, so no mail will be sent.

However, before sending the quoted message, it needs to specify the sender's mail. So that's why you need to specify it. Besides that, you also need to define the owner's mail domain, because it's needed for the EHLO payload.


What about doing something like this (I'm using mongo_mapper, so this may be different in your situation):

class User
    include MongoMapper::document
    ...
    key mail, String, :required => true
    ...
    validate :validate_mail
    ...
    def validate_mail
        if !EmailCheck.run(self.mail, "no-reply@yourdomain.com", self.mail.split('@')[1]).valid?
            errors.add :mail, "is invalid."
        end
    end 
end


If you need it for a ruby script, you can do something like this. Just require the email check found on lib of that gem.

require 'email_check.rb'

is_valid = EmailCheck.run("kiran@joshsoftware.com", "no-reply@joshsoftware.com", "joshsoftware.com").valid?

puts "is valid: #{is_valid}"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜