2011-01-19 39 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 
相关问题