[英]SMTP Password with special characters - utf8 - java mail - encoding issue?
I'm trying to send an email via java.mail SMTP. 我正在尝试通过java.mail SMTP发送电子邮件。 I have 2 mail accounts using the same provider and settings:
我有2个使用相同提供商和设置的邮件帐户:
The first one works. 第一个作品。 The second one says
535 Authentication credentials invalid
. 第二个说
535 Authentication credentials invalid
。
I'm using java.mail 1.5. 我正在使用java.mail 1.5。
Here's my code: 这是我的代码:
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());
Do I need to encode the password somehow? 我是否需要以某种方式对密码进行编码?
Thanks in advance. 提前致谢。
I now tried to login via telnet. 我现在尝试通过telnet登录。 Same problem.
同样的问题。 So this isn't related to Java, but it may be some common SMTP issue.
因此,这与Java无关,但可能是一些常见的SMTP问题。
Using the E-Mail account using Apple Mail on Mac and iPhone works without any issues. 在Mac和iPhone上使用Apple Mail使用电子邮件帐户可以正常工作。
If you have non-ASCII special characters, you'll need to use JavaMail 1.6 and set the mail.mime.allowutf8
Session property. 如果您使用非ASCII特殊字符,则需要使用JavaMail 1.6并设置
mail.mime.allowutf8
会话属性。 And the server needs to support the SMTPUTF8 extension. 服务器需要支持SMTPUTF8扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.