我正在尝试通过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 是不符合 RFC 5322 的 550-5.7.1:550-5.7.1 缺少"发件人"标头。550-5.7.1 为了减少发送到Gmail的垃圾邮件数量,此邮件有蜜蜂n550-5.7.1 被阻止。请访问550-5.7.1 https://support.google.com/mail/?p=RfcMessageNonCompliant550 5.7.1 并查看 RFC 5322 规范以获取更多信息。
其他提供程序未阻止该消息。那么希望它应该只是缺少的 FROM 标头。
您应该关注错误消息。
550-5.7.1 not RFC 5322 compliant: 550-5.7.1 'From' header is missing.
据我了解,使用 MimeMessage,您可以使用 setFrom(( 设置 FROM-Header。
类哑剧消息