- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题是:我需要发现一个 IP 和端口是否正在运行 SMTP 服务。为此,我使用 SMTPClient 尝试打开连接。我正在使用下面的代码。
private static boolean validateSMTP(String ip, int port, int timeOut) {
SMTPClient smtp = new SMTPClient();
try {
smtp.setConnectTimeout(timeOut);
smtp.connect(ip, port);
return true;
} catch (SocketException e) {
LogAplication.Warning("Ops... something wrong", e);
} catch (IOException e) {
LogAplication.Warning("Ops... something wrong", e);
}
finally{
smtp = null;
}
return false;
}
它工作正常,我已经得到了预期的结果,但超时一直是我的问题。例如:如果我尝试 ip: 127.0.0.1 和端口 80(IIS 开放端口),连接步骤需要很长时间(比超时中定义的时间长得多)才能引发异常
java.net.SocketException: Connection reset
在这种情况下如何设置超时?或者存在另一种方法来进行我的简单测试?
最佳答案
查看后grepCode ,我发现这个方法 connect(string host, int port) :
Opens a Socket connected to a remote host at the specified port and originating from the specified local address and port. Before returning, _connect Action() is called to perform connection initialization actions.
当端口被另一个服务打开时,套接字被打开,不会导致超时(通过套接字),但“connectAction()”抛出异常因此,我需要为 SMTPClient 设置一个全局超时,该超时由套接字连接和“connectAction()”内部使用。我这样做是为了解决我的问题:
smtp.setDefaultTimeout(timeOut);
有了这个,现在我已经得到了预期的结果,打开抛出异常的端口,当然还有成功连接 SMTP 服务。
关于java - SMTPClient 设置开放端口的超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29799063/
我正在尝试从本地主机发送邮件.. 在执行此操作时,我有来自不同站点的方法来发送邮件..但是在执行此操作时,我对 smtpClient.send() 感到困惑和smtpClient.SendAsync(
我正在从事一个项目(不幸的是)需要允许的最大框架是 .NET 4。 在这个项目中,我尝试使用 SendAsync() 异步发送电子邮件,但由于某种原因,它发送失败(或者更确切地说,它只是不发送)。简单
考虑到 SmtpClient 有一个我没有使用的 SendAsync 方法,因此假设 StmpClient.Send 是同步的是否安全?我用它来发送带有临时文件附件的电子邮件,想知道我是否可以在之后立
我在多台(不是说:所有)Windows 8.x 机器上面临以下问题: 运行这段代码: var message = new MailMessage(); message.From = new MailA
如标题所述,将“SmtpClient::EnableSsl”设置为 true 的“System::Net::Mail::SmtpClient”需要哪些端口? documentation on the
如果我已将一些电子邮件排队等待通过 System.Net.Mail.SMTPClent 发送,我在哪里可以找到这封邮件?对于 Windows SMTP 客户端,它位于 C:\inetpub\mailr
.NET SmtpClient 对象中的超时默认值是多少?它是什么时间单位(秒、毫秒等)? 最佳答案 默认值为 100,000(100 秒)。 http://msdn.microsoft.com/en
我尝试使用 SmtpClient.Send() 从 c# 发送电子邮件,但它总是进入垃圾箱。如果我从 Outlook 发送它,它工作正常。无论如何要解决这个问题?有人告诉我修改电子邮件标题,但我不知道
我正在尝试使用 C# 创建一个小型应用程序来发送电子邮件,但即使使用端口 587 (GMail) TLS 或 465 (GMail SSL) 我也无法让它工作。我不确定是什么导致了我的问题,我应该编辑
当我使用 SmtpClient 发送电子邮件时,我发现了一个奇怪的行为: 送货时间太长。 已送达两次。 SmtpClient client = new SmtpClient(); client.Hos
我正在使用以下代码发送电子邮件: using (var mailMessage = new MailMessage("from@example.com", "to@example.com")) {
我遇到了一个让我抓狂的问题!!!我有一个用于发送电子邮件的小型 Delphi 7 应用程序(使用 Indy 9 组件套件)并且一切正常。我正在尝试开发一个执行相同操作的 C# 应用程序 (Visual
我的 Smtpclient 正在使用以下设置 SmtpClient client = new SmtpClient(); client.Host = server; client.UseDefault
我的问题是:我需要发现一个 IP 和端口是否正在运行 SMTP 服务。为此,我使用 SMTPClient 尝试打开连接。我正在使用下面的代码。 private static boolean v
我有一个指向我公司邮件服务器的 SmtpClient。我能够成功地向/从该域上的地址发送电子邮件。 但是,我需要为应用程序的用户重置密码和通知。这些用户使用他们自己的电子邮件地址(多个不同的域)注册。
SmtpClient 发送方法返回无效。有什么办法可以得到服务器响应吗?我是否只是假设它是成功的,除非它抛出异常? 我指的是类... http://msdn.microsoft.com/en-us/l
我正在创建每 5 分钟发送一批电子邮件的 Windows 服务。 我想每 5 分钟发送 10-100 封电子邮件。这是极端情况。每 5 分钟发送一次批处理,通常最多包含 10 封电子邮件。 我正在使用
我已经设置了 SmtpClient 类的超时属性,但它似乎不起作用,当我给它一个 1 毫秒的值时,执行代码时超时实际上是 15 秒。我从 msdn 中获取的代码. string to = "jane@
我正在从 Java 向我们的客户发送电子邮件。而且我们的 SMTP 没有任何身份验证。因此,我在 Java 中使用以下代码无需身份验证即可发送: Properties props = new Prop
我有一个 C# 服务 那个连续运行 使用用户凭据(即不是本地系统 - 虽然我想更改但我无法更改)。在大多数情况下,该服务似乎运行正常,但它经常爆炸和 无故重启 (服务管理器设置为在崩溃时重新启动服务)
我是一名优秀的程序员,十分优秀!