简体   繁体   English

验证Java中的mailto链接

[英]validating mailto links in java

Is it possible to check whether an email is a valid email or not? 是否可以检查电子邮件是否为有效电子邮件?

For checking whether a link is a valid one or not I am checking like this... 为了检查链接是否有效,我正在像这样检查...

URL url = new URL(" http://www.google.com "); URL url =新URL(“ http://www.google.com ”);
URLConnection connection = url.openConnection(); URLConnection连接= url.openConnection();

        if ( connection instanceof HttpURLConnection)
        {
            HttpURLConnection httpConnection = (HttpURLConnection)connection;
            httpConnection.connect();
            return httpConnection.getResponseCode();
        }

now if its a mialto how do I do it? 现在,如果它是mialto怎么办?
URL url = new new URL("mailto:someone@gmail.com"); URL url =新的新URL(“ mailto:someone@gmail.com”);

The answer is not really Java related, the short form is: you can't without actually sending an email to that address. 答案不是真的与Java相关,简写为:您必须在没有实际发送电子邮件到该地址的情况下才能这样做。 See my answer to a similar question here: Email SMTP validator 在这里查看我对类似问题的回答: 电子邮件SMTP验证程序

To validate whether an email address is valid or not, you can read http://azcarya.blogspot.com/2007/10/email-address-validation.html . 要验证电子邮件地址是否有效,您可以阅读http://azcarya.blogspot.com/2007/10/email-address-validation.html To check whether an email address exists or not, you can shoot an email to the address and check for the server reply, in case you receive an email address not valid status mail. 要检查电子邮件地址是否存在,如果您收到的电子邮件地址不是有效的状态邮件,则可以向该地址发送电子邮件并检查服务器答复。

this smells. 这闻起来。 why would you want to do this? 你为什么想做这个? validate e-mails of your customers when they sign up for your service and then you can be sure their email exists. 在客户注册您的服务时验证他们的电子邮件,然后可以确保他们的电子邮件存在。 but checking whether other peoples' email exists smells. 但是检查其他人的电子邮件是否存在气味。

I do believe there is a reason why you can't ping an email-address. 我确实认为您无法ping电子邮件地址是有原因的。 Spammers would love to have the opportunity;) 垃圾邮件发送者希望有机会;)

Email clients give you an option to not download pictures, and that's because that would allow the spammers to see that someone actually read the mail, and thus someone is using the address. 电子邮件客户端为您提供了一种不下载图片的选项,因为这将使垃圾邮件发送者看到有人实际阅读了邮件,从而有人在使用该地址。 Another way is to have a "don't send me more of this crap" button, when someone clicks it, you know it's a used address. 另一种方法是使用“不要向我发送更多此废话”按钮,当有人单击它时,您知道它是一个二手地址。

to check if email address is really an email address you could to 检查电子邮件地址是否真的是您可以使用的电子邮件地址

try{
    InternetAddress a = new InternetAddress("my@email.com");
    a.validate()
}catch(Exception e){
    //INVALID
}

to check wether email address exists is another story... 检查是否存在电子邮件地址是另一回事...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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