简体   繁体   中英

How can I prevent users from using fake emails, which is causing my mail server to fail?

I'm using SendGrid to send registration emails to users, our users are using fake emails to register. Users cannot access the website which is goof protection for our site. But, when SendGrid tries to send them the email it bounces.

Unfortunately, we are facing more than 20-30% of fake emails on daily basis, which might lead to SendGrid blocking us altogether. What's the solution programmatically or web perspective?

Disclaimer: I know this is not a programming question, but not sure where should I ask it.

Change the approach if possible. Ask to your users to send you an email to register themselves (ie an empty email) and reply to this email with their authentication information. At this point you are sure that they are the owner of the mail address (otherwise they will not receive the credentials) and that the email is not fake.

Simply drop the incoming bounces, you do not need them. Additionally, you might want to look at Simple Email Service from Amazon instead to get rid off problems with your own mail setup.

At the end of the day, if you want to send emails, you have to live with the returns hence you have to scale your server/service to deal with it.

You'll want to do everything you can to make sure users are signing up with valid email addresses. Here's a few ways to do that:

  • Force new users to validate their email address before granting them access to the site. Email addresses can be validated by sending them an email containing a link that must be clicked to validate the account.

  • Use type="email" on the input field used to enter email addresses. Good browsers (like chrome) will force a simple regex match before allowing the form to submit.

  • Use a regex to filter out obviously bad emails. There's a ton of email addresses regexes floating around, suggesting looking at ones used in larger open source web frameworks, such as Django.

  • Mailgun provides an API to verify email addresses. It should be used intelligently (ie: dont spam it with every signup), and can catch common misspellings and even suggest typo fixes. https://documentation.mailgun.com/api-email-validation.html

If you're using SendGrid mailing list, you have the option to use MailboxValidator to import your list, screen for invalid emails and then update your list automatically at SendGrid.

https://www.mailboxvalidator.com/resources/articles/how-to-import-email-list-from-sendgrid/

But if you are using SendGrid API, you could try to integrate the MailboxValidator free API (300 free validations every 30 days) into your codes before you call the SendGrid API.

https://www.mailboxvalidator.com/api-single-validation

Sample Java code for calling the API

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Hashtable;
import java.util.Map;

public class test {
    public static void main(String[] args) {
        try {
            String key = "Enter_License_Key";
            Hashtable<String, String> data = new Hashtable<String, String>();
            data.put("format", "json");
            data.put("email", "Enter_Email");

            String datastr = "";
            for (Map.Entry<String,String> entry : data.entrySet()) {
                datastr += "&" + entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8");
            }
            URL url = new URL("https://api.mailboxvalidator.com/v1/validation/single?key=" + key + datastr);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");

            if (conn.getResponseCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

            String output;

            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }
            conn.disconnect();
        }
        catch (MalformedURLException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM