2012-11-10 47 views
3

我已成功完成validation of mail address但我想要驗證電子郵件地址的一些建議。要點是當用戶輸入一個電子郵件ID時,應該檢查它是真實的還是僞造的ID。 有什麼建議嗎?驗證電子郵件地址是否存在

+3

你可以使用正則表達式來設置驗證規則 http://www.mkyong.com/regular-expressions/10-java-regular -expression-examples-you-should-know /但肯定知道電子郵件ID是正確的不可能我猜 –

+0

你的意思是驗證?順便說一句!你試過了什麼? – RobinHood

+0

我不想驗證因爲我已經完成了這個。我只是想檢查輸入的電子郵件地址是否存在。這就是它。 –

回答

1

不,該設施不可用。只有當您擁有自己的郵件服務器時,您才能驗證您有權檢查郵件標識是否有效。或者當你擁有其他服務器時,你可以獲得所有其他郵件服務器的鏡像,然後你可以驗證,所以如果你只是郵件編號的用戶,那麼你可以驗證郵件編號是否有效。

您只能通過模式檢查來驗證郵件標識的正確格式。

玩得開心

+0

其實在我的應用程序,我只是從用戶的電子郵件地址,只是想檢查它是否存在或沒有。沒有其他。因爲sumtimes用戶jss輸入假地址,我不希望用戶這樣做。 –

+0

@SnehaJain你不能這樣做,因爲沒有郵件服務器允許檢查他們的郵件ID細節。只有當你有自己的郵件服務器時,你纔可以獲得鏡像鏡像,這是付費的......所以你不能。\ –

+0

讓我解釋清楚..你都看到網站,要求你從不同sites.log登錄從臉書,從Gmail等登錄,所以我只想當用戶輸入他/她的電子郵件地址,那麼它應該存在。 –

1

您只能檢查是否使用regular expression進入E-mail id is validate or not,它無法檢查id是否存在與否?根據我的知識。

檢查出這個link其已在回答

+0

這是絕對正確的;郵件服務器不允許你收集這些數據。 (*因此,當你發送一封假郵件時,爲什麼你會收到一封PostMaster郵件*) – Eric

+0

讓我來解釋清楚..所有看到的網站都會要求你從不同的站點登錄,比如登錄facebook,登錄gmail等。所以我只是想當用戶輸入他/她的電子郵件地址時,它應該存在。 –

0
public static void main(String[] args) throws Exception { 
String email = null; 
String dns = null; 

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 
System.out.print("Enter email address to validate: "); 
email = reader.readLine(); 
System.out.print("Enter DNS hostname to perform domain validation (e.g. ns.myhost.com): "); 
dns = reader.readLine(); 
// create EmailInspector instance 
EmailInspector inspector = new EmailInspector(); 

// enable debugging 
inspector.setDebug(true); 

// set DNS server 
inspector.setNameserver(dns); 

// set validation level 
inspector.setEmailInspectionLevel(inspector.DOMAIN_VALIDATION); 

// validate email 
inspector.validate(email); 
} 

} 






. Create new EmailInspector instance. 
    . Enable debugging. 
    . Set DNS server to be used for looking up domains. 
    . Set validation level. 
    . Validate email address. 
0
Properties props = System.getProperties(); 

    props.put("mail.smtp.user", senderEmail); 
    props.put("mail.smtp.host", "smtp.gmail.com"); 
    props.put("mail.smtp.port", "465"); 
    props.put("mail.smtp.starttls.enable", "true"); 
    props.put("mail.smtp.debug", "true"); 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.socketFactory.port", "465"); 
    props.put("mail.smtp.socketFactory.class", 
      "javax.net.ssl.SSLSocketFactory"); 
    props.put("mail.smtp.socketFactory.fallback", "false"); 

    // Required to avoid security exception. 
    email.MyAuthenticator authentication = 
      new email.MyAuthenticator(senderEmail,senderMailPassword); 
    Session session = 
      Session.getDefaultInstance(props,authentication); 
    session.setDebug(true);