gpt4 book ai didi

java - Android javamail 501 5.5.4 无效参数

转载 作者:太空宇宙 更新时间:2023-11-04 13:08:30 24 4
gpt4 key购买 nike

我正在尝试使用 Mailgun 发送电子邮件。根据 mailgun,我使用以下代码:

public static void TestMail() throws Exception
{

Properties props = System.getProperties();
props.put("mail.smtps.host","smtp.mailgun.org");
props.put("mail.debug", "true");
props.put("mail.verbose", "true");
props.put("mail.smtps.auth","true");
Session session = Session.getInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("fromaddress@gmail.com"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("toaddress@gmail.com", false));
msg.setSubject("Hello");
msg.setText("Testing some Mailgun awesomness");
msg.setSentDate(new Date());
SMTPTransport t =
(SMTPTransport)session.getTransport("smtps");
t.setStartTLS(true);
t.connect("smtp.mailgun.com", "postmaster@sandbox86837*********.mailgun.org", "b071d**********");
t.sendMessage(msg, msg.getAllRecipients());
System.out.println("Response: " + t.getLastServerResponse());
t.close();


}

我正在使用从以下位置下载的 javamail api:https://code.google.com/p/javamail-android/downloads/list

现在在调试中显示以下信息:

DEBUG: JavaMail version 1.4.1
DEBUG: not loading file: /system/lib/javamail.providers
DEBUG: java.io.FileNotFoundException: /system/lib/javamail.providers: open failed: ENOENT (No such file or directory)
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: not loading resource: /META-INF/javamail.default.providers
DEBUG: failed to load any providers, using defaults

DEBUG: not loading resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: not loading file: /system/lib/javamail.address.map
DEBUG: java.io.FileNotFoundException: /system/lib/javamail.address.map: open failed: ENOENT (No such file or directory)
DEBUG: failed to load address map, using defaults
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc.,1.4.1]
DEBUG SMTP: useEhlo true, useAuth true


DEBUG SMTP: trying to connect to host "smtp.mailgun.com", port 465, isSSL true
220 ak47 ESMTP ready
DEBUG SMTP: connected to host "smtp.mailgun.com", port: 465
EHLO
501 5.5.4 Invalid argument
HELO
501 5.5.4 Invalid argument

我不知道这个错误意味着什么?当我用谷歌搜索时,没有人指出错误的确切原因或原因。可能是 ssl 或者我的系统缺少一些 java 库?或者我下载的java lib不正确。

但是正如您在调试中看到的那样,它能够成功连接到 smtp.mailgun.com。那为什么会出现这个错误呢?请帮助我。

谢谢

最佳答案

您要连接的服务器要求 HELOEHLO 的参数是主机名或 IP 地址。

您的代码似乎也没有发送。

RFC(RFC2821第29页)似乎有些含糊...

...the client SHOULD send an IP address if no hostname is available

如果这是一项要求,则应使用“必须”一词。但 HELO/EHLO 的语法描述似乎表明该参数是必需的。

第 3.6 节(关于域):

  • The domain name given in the EHLO command MUST BE either a primary host name (a domain name that resolves to an A RR) or, if the host has no name, an address literal as described in section 4.1.1.1.

关于java - Android javamail 501 5.5.4 无效参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34193084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com