2011-01-19 42 views

回答

0

使用URI來指定網絡資源(例如SMTP服務器)可能是您看到的「接受」格式(SMTP URI)的最後一個東西,就像smtp:// user:host @ example.com:port或者也許只是smtp://example.com。您將使用通用的URI解析庫來提取各種組件。

還有一個 RFC草案SMTP URL小號

+0

我已經使用了`java.net.URI` :),並且工作得很好。看看我自己的答案。 – OscarRyz 2011-01-19 18:40:52

3

雖然有SMTP URL Scheme,我從來沒有見過任何人使用它。實際上,大多數應用程序爲主機,端口,用戶名和密碼提供了四個單獨的字段。但是如果你真的需要將這四個組件放在一個字符串中,那麼你提供的例子可能就是這樣的最有名的格式。

+0

我用它在方便WordPress插件。 https://github.com/szepeviktor/smtp-uri – 2015-08-09 18:23:45

0

我認爲這是可行的。

我想添加爲答案,我如何使用java.net.URI類從該URI獲取信息。

class Demo { 
    public static void main(String ... args) throws Exception { 
    System.out.println(inspect(new URI("smtp://user:[email protected]:25"))); 
    } 
    // invoke all the getXyz methods on object and construct 
    // a string with the result. 
    private static String inspect(Object o) throws Exception { 
    StringBuilder builder = new StringBuilder(); 
    for(Method m : o.getClass().getMethods()) { 
     String name = m.getName(); 
     if(name.startsWith("get")) { 
     builder.append(name) 
     .append(" = ") 
     .append(m.invoke(o)) 
     .append("\n"); 
     } 
    } 
    return builder.toString(); 
    } 
} 

輸出

getAuthority = user:[email protected]:25 
getFragment = null 
getPath = 
getQuery = null 
getScheme = smtp 
getHost = host 
getPort = 25 
getUserInfo = user:port 
getRawAuthority = user:[email protected]:25 
getRawFragment = null 
getRawPath = 
getRawQuery = null 
getRawSchemeSpecificPart = //user:[email protected]:25 
getRawUserInfo = user:port 
getSchemeSpecificPart = //user:[email protected]:25 
getClass = class java.net.URI 
相關問題