【发布时间】:2018-04-12 10:43:47
【问题描述】:
我正在尝试通过 Javamail 和 smtp 从 Android 应用程序发送邮件。如果我输入“smtp.gmail.com”和我的 gmail 凭据,它运行良好,但对于 1&1,它不起作用。我在这里错过了什么吗?
这是我的代码:
public class SendMail extends javax.mail.Authenticator {
private String mailhost = "smtp.1und1.de";
private String port = "465";
private String user;
private String password;
private Session session;
static {
Security.addProvider(new JSSEProvider());
}
public SendMail(String user, String password) {
this.user = user;
this.password = password;
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", mailhost);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", port);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.enable","true");
props.put("mail.smtp.socketFactory.port", port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
session = Session.getInstance(props, this);
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
public synchronized void sendMail(String subject, String body,
String recipients) throws Exception {
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
message.setSender(new InternetAddress(user));
message.setSubject(subject);
message.setDataHandler(handler);
if (recipients.indexOf(',') > 0)
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
else
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
Transport.send(message);
}
}
提前致谢
好的,我刚刚注意到电子邮件已发送,但被 gmail 阻止了。
我们的系统检测到此消息 e 是 550-5.7.1 不符合 RFC 5322: 550-5.7.1 缺少“发件人”标头。 550-5.7.1 为减少发送到 Gmail 的垃圾邮件数量,此邮件已被蜜蜂 n 550-5.7.1 被阻止。请拜访 550-5.7.1https://support.google.com/mail/?p=RfcMessageNonCompliant 550 5.7.1 并查看 RFC 5322 规范以获取更多信息。
其他提供商没有阻止消息。 那么它希望应该只是缺少的 FROM Header。
【问题讨论】:
-
首先,修复所有这些common JavaMail mistakes。然后发布JavaMail debug output。
标签: android smtp jakarta-mail