- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在创建一个用java发送电子邮件的应用程序,一切都已设置并且工作正常。但错误是当我尝试登录 Hotmail 帐户时,它显示我在 catch block 中给出的电子邮件和密码不正确的错误。但是当我第一次登录yahoo或gmail时,它会登录hotmail,之后我可以登录Hotmail,但我无法先登录hotmail,为什么?!代码如下
private void cmd_loginActionPerformed(java.awt.event.ActionEvent evt) {
user = txt_user.getText();
pass = txt_pass.getText();
int combo = combo_ac.getSelectedIndex();
if(combo==0){
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session sessin = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(user+"@gmail.com", pass);
}
}
);
new Gmail().setVisible(true);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Incorrect Email or Password!");
}
}else if(combo==1){
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.live.com");
props.put("mail.smtp.socketFactory.port", "25");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "25");
Session sessin = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(user+"@hotmail.com", pass);
}
}
);
new Hotmail().setVisible(true);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Incorrect Email or Password!");
}
}else if(combo==2){
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.mail.yahoo.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session sessin = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(user+"@yahoo.com", pass);
}
}
);
new Yahoo().setVisible(true);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Incorrect Email or Password!");
}
}
}
最佳答案
这个article会解释为什么显然您可以在登录 gmail 或 yahoo 后登录您的 hotmail 帐户。实际上,您登录的帐户与您第一次尝试时使用的帐户相同。问题是您正在使用 Session#getDefaultInstance()
而不是 Session#getInstance()
:
The
Session.getDefaultInstance
method creates a new Session the first time it's called, using the Properties that are passed. Subsequent calls will return that original Session and ignore any Properties you pass in. If you want to create different Sessions with different properties,Session.getDefaultInstance
won't do that. [...] Always useSession.getInstance
to avoid this problem.
但是,它并不能解释为什么您无法登录到您的 hotmail 帐户,但您应该发布异常堆栈跟踪,以便我们可以帮助您。
更新:
基于此堆栈跟踪:
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
这意味着您必须根据 Hotmail 要求将 mail.smtp.starttls.enable
属性设置为 true
:
Select TLS for Use the following type of encrypted connection under Outgoing server (SMTP), and then click OK. Note The Outgoing Server (SMTP) box should be set to port 25. If port 25 is blocked in the network or by your ISP, you can set SMTP port to 587.
注意:摘自Configure Outlook to connect to an MSN email account .
尝试登录 Hotmail 帐户时,您应该仅将以下行添加到代码中:
props.put("mail.smtp.starttls.enable", "true");
另外,不要忘记按照我上面的建议将 Session.getDefaultInstance
替换为 Session.getInstance
。
关于java - java中的hotmail登录错误(IDE : Netbeans),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18388581/
我正在寻找一个编辑器/IDE,它可以为不是专门为它构建的语言提供在编码时很好的功能(例如:能够点击到函数定义)。通过这些,我想到了为非常特定的目的而设计的语言,并且通常只被一个小社区使用。换句话说,那
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
有简单的解释性编程语言,实际上还有控制台 interpreter.exe。 需要按 F5 对语法进行着色、自动完成和执行。 (如果有可能进行“调试”——那就太棒了!) 我从来没有做过这样的事情。 有许
我只是想知道是否有任何可以在我的黑莓上运行的 IDE。我的旧 Palm 有 C 和 BASIC 翻译。 C 板上使用 Palm 的内置文本编辑器,但 BASIC 解释器内置了自己的简单编辑器。 黑莓或
我正在制作一个文件编辑器,并希望为我的用户提供一个不错的 IDE,可以在其中在浏览器上编辑他们的 html/css 文件。是否有任何编辑器与 TinyMCE 类似,但它不是一个所见即所得的编辑器,它更
是否有一个带有集成调试器的D IDE? 最佳答案 Descent可以使用调试器。不完全是您的要求,但是... 关于ide - 是否有一个带有集成调试器的D IDE?,我们在Stack Overflow
每个程序员都知道工具很重要,对于开发人员来说,没有比用于编码的 IDE 更重要的工具了。在过去的几年里,IDE-s 成为标准,在这个领域看到创新并不常见。您可以推荐哪些 IDE 具有创新性,它们引入了
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
我目前正在学习Ironpython和热爱软件,但我希望从使用notepad ++和cmd.exe继续前进,并尝试使用果汁多一点的东西。 我最近了解到Iron python studio不支持Iron
我主要从事 Java 和 C/C++ 开发,但我开始做更多的 Web 开发(PHP、Rails)和 Eiffel(学习一门新语言总是好的)。 目前,我使用 Eclipse for Java、C/C++
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
是否有 280Atlas (280atlas.com)(免费/商业)的替代品? 其中哪些是成熟的? 最佳答案 您可以使用 nib2cib ,这几乎是相同的想法,但它使用界面构建器(xcode的一部分)
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
IDE 的目标是提高生产力。他们在这方面做得很好。重构、导航、内联文档、自动完成有助于极大地提高生产力。 但是:每个工具都是武器 .相同的 IDE 有助于生成块代码。一些 IDE 功能会导致产生不良代
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我正在寻找一些功能强大的C / C ++编程环境。实际上,我唯一需要的就是强大的源导航+创建工具。免费或商业都无所谓。我更喜欢一些linux工具,但是它不一定是必需的linux应用。 我需要的是一种具
我刚开始学习 D。有人知 Prop 有自动格式化功能的 D IDE 吗? Eclipse 的 DDT 似乎除了语法高亮之外没有任何其他功能。 最佳答案 我相信,目前 MonoDevelop + Mon
我有兴趣为一个副项目构建一个新风格的 IDE。主要是为了取消类固醇IDE上的普通记事本。我正在为已经尝试过的或者你已经看到(或没有看到)看起来很酷并且在 IDE 中有用的东西寻找一些灵感。我可以解决的
我需要维护一些 VB6 应用程序,并且在涉及枚举名称时遇到了一个奇怪的问题。 VB6 中的 Intellisense 应该工作的方式是,如果我的变量名称被定义为,例如,Dim Abraxis as S
正如标题所说,我看到很多编辑将宏录制作为一项功能吹捧,但自己却找不到利用这些功能的方法。那你能用它做什么呢?您可以记录鼠标移动和/或击键的类型?对外面的人真的那么有帮助吗?具体来说,我处理的 Ecli
我是一名优秀的程序员,十分优秀!