带有特殊字符的 SMTP 密码 - utf8 - java 邮件 - 编码问题?
SMTP Password with special characters - utf8 - java mail - encoding issue?
我正在尝试通过 java.mail SMTP 发送电子邮件。我有 2 个使用相同提供商和设置的邮件帐户:
- 使用没有特殊字符的短密码
- 使用带有特殊字符的长密码 (* > / % !)
第一个有效。第二个说 535 Authentication credentials invalid
.
我正在使用 java.mail 1.5.
这是我的代码:
Properties props = new Properties();
props.put("mail.smtps.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.1und1.de");
props.put("mail.smtp.port", "465");
Session session = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("foo@example.org", "$§$&/&%§$!><>");
}
});
Transport transport = session.getTransport("smtps");
transport.connect("smtp.1und1.de", username, password);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("foo@example.org"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("bar@example.org"));
message.setSubject("subject");
message.setText("text");
transport.sendMessage(message, message.getAllRecipients());
我需要以某种方式对密码进行编码吗?
提前致谢。
编辑:
我现在尝试通过 telnet 登录。同样的问题。所以这与 Java 无关,但它可能是一些常见的 SMTP 问题。
在 Mac 和 iPhone 上使用 Apple Mail 的电子邮件帐户没有任何问题。
如果您有非 ASCII 特殊字符,则需要使用 JavaMail 1.6 and set the mail.mime.allowutf8
会话 属性。并且服务器需要支持SMTPUTF8扩展。
我正在尝试通过 java.mail SMTP 发送电子邮件。我有 2 个使用相同提供商和设置的邮件帐户:
- 使用没有特殊字符的短密码
- 使用带有特殊字符的长密码 (* > / % !)
第一个有效。第二个说 535 Authentication credentials invalid
.
我正在使用 java.mail 1.5.
这是我的代码:
Properties props = new Properties();
props.put("mail.smtps.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.1und1.de");
props.put("mail.smtp.port", "465");
Session session = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("foo@example.org", "$§$&/&%§$!><>");
}
});
Transport transport = session.getTransport("smtps");
transport.connect("smtp.1und1.de", username, password);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("foo@example.org"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("bar@example.org"));
message.setSubject("subject");
message.setText("text");
transport.sendMessage(message, message.getAllRecipients());
我需要以某种方式对密码进行编码吗?
提前致谢。
编辑:
我现在尝试通过 telnet 登录。同样的问题。所以这与 Java 无关,但它可能是一些常见的 SMTP 问题。
在 Mac 和 iPhone 上使用 Apple Mail 的电子邮件帐户没有任何问题。
如果您有非 ASCII 特殊字符,则需要使用 JavaMail 1.6 and set the mail.mime.allowutf8
会话 属性。并且服务器需要支持SMTPUTF8扩展。