SMTP 服务器是否有可接受的语法? (以及如何解析它)

发布于 2024-10-13 00:20:44 字数 123 浏览 7 评论 0原文

我见过这样的事情:

user:password@smtpserver:port

过去,但我不确定某个库是否解析它来构建属性来创建会话,或者是否存在某种可接受的格式。

I've seen things like:

user:password@smtpserver:port

In the past, but I'm not sure if the some library parsed that to build a properties to create a session or is there some sort of accepted format.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烙印 2024-10-20 00:20:44

使用 URI 来指定网络资源(例如 SMTP 服务器)可能是最接近“接受”格式的东西,SMTP URI 类似于 smtp://user:[email protected]:port 或可能只是 smtp://example.com 。您可以使用通用 URI 解析库来提取各种组件。

还有一个 RFC 草案SMTP URL

Using an URI for specifying a network resource, such as an SMTP server is probably the cloeset thing to a "accepted" format you'd see, an SMTP URI, would be something like smtp://user:[email protected]:port or perhaps just smtp://example.com . You'd use a generic URI parsing library to extract the various components.

There's also an old RFC draft for SMTP URLs

墨洒年华 2024-10-20 00:20:44

虽然有 SMTP URL 方案,但我有从未见过有人使用它。实际上,大多数应用程序都提供四个单独的字段:主机、端口、用户名和密码。但是,如果您确实需要将这四个组件放入一个字符串中,那么您提供的示例可能是此类内容的最著名格式。

While there is a SMTP URL Scheme, I have never seen anyone use it. In practice, most applications provide four separate fields for host, port, user name and password. But if you really need to put those four components into a single string, the example you provided is probably the best-known format for something like this.

谎言 2024-10-20 00:20:44

我认为这会起作用。

我想添加作为答案,我如何使用 java.net.URI 类从该 URI 获取信息。

class Demo { 
  public static void main( String ... args ) throws Exception  { 
    System.out.println( inspect( new URI("smtp://user:port@host: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:port@host:25
getFragment = null
getPath =
getQuery = null
getScheme = smtp
getHost = host
getPort = 25
getUserInfo = user:port
getRawAuthority = user:port@host:25
getRawFragment = null
getRawPath =
getRawQuery = null
getRawSchemeSpecificPart = //user:port@host:25
getRawUserInfo = user:port
getSchemeSpecificPart = //user:port@host:25
getClass = class java.net.URI

I think that would work.

I would like to add as answer, how I'm using java.net.URI class get information from that URI.

class Demo { 
  public static void main( String ... args ) throws Exception  { 
    System.out.println( inspect( new URI("smtp://user:port@host: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();
  }
}

Output

getAuthority = user:port@host:25
getFragment = null
getPath =
getQuery = null
getScheme = smtp
getHost = host
getPort = 25
getUserInfo = user:port
getRawAuthority = user:port@host:25
getRawFragment = null
getRawPath =
getRawQuery = null
getRawSchemeSpecificPart = //user:port@host:25
getRawUserInfo = user:port
getSchemeSpecificPart = //user:port@host:25
getClass = class java.net.URI
一袭白衣梦中忆 2024-10-20 00:20:44

正在配置节点应用程序,但很难获得它。

smtp://username:password@smtphost:port

有趣的是我的密码有一个“@”,所以它假设主机名已经开始。
用户名还有一个“@”服务器,但它很好,因为它由冒号“:”分隔,

希望这有帮助。
干杯

Was configuring node app and had a hard time getting it.

smtp://username:password@smtphost:port

The funny part was my password was having an '@' so it was presuming the hostname has started.
The username also had an '@' server but it was good as it was separated by the colon ":"

Hope this helps.
Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文