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("[email protected]","[email protected]","joshsoftware.com").valid?
It's return 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 [email protected]
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, "[email protected]", self.mail.split('@')[1]).valid?
errors.add :mail, "is invalid."
end
end
end