gpt4 book ai didi

java - 尝试使用JavaMail

转载 作者:行者123 更新时间:2023-12-01 12:42:46 25 4
gpt4 key购买 nike

所以我正在尝试创建一个服务器,我可以在其中将发件人电子邮件更改为我想要的任何内容。我尝试过注册免费的 SMTP 服务器,但我不确定是否允许我做我想做的事情。如果这不起作用,有人可以引导我到允许我执行此操作的 SMTP 服务器吗?

package Mailer2;
import java.util.Date;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class mailer2 {

public static void main(String[] args) throws AddressException, MessagingException{
Properties prop = new Properties();
prop.put("mail.smtp.host", "ssrs.reachmail.net");
prop.put("mail.smtp.port", "587");

Session session = Session.getDefaultInstance(prop, new Authenticator() {

// Override method to Authenticate to mail server
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("MCA28\\admin", "NotShowingPassword");
}
});

session.setDebug(true);

MimeMessage Msg = new MimeMessage(session);

Msg.setFrom(new InternetAddress("yo@yo.com"));

Msg.setRecipients(RecipientType.TO, "emailtosend@gmail.com");

Msg.setSubject("afa");

// Initiate MimeBodyPart for filling email content
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText("Message Content");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messagePart);
Msg.setContent(multipart);

// Email Sending process
Transport.send(Msg);

}



}

这是日志:

DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "ssrs.reachmail.net", port 587, isSSL false
220 ssrs.reachmail.net rmsmtp 3.1.0a 4a1db2f953
DEBUG SMTP: connected to host "ssrs.reachmail.net", port: 587

EHLO 192.168.1.4
250-EASYSMTP
250-8BITMIME
250-SIZE 102400000
250-AUTH PLAIN LOGIN
250 STARTTLS
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "102400000"
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<yo@yo.com>
503 error: not authorized, use AUTH
DEBUG SMTP: got response code 503, with response: 503 error: not authorized, use AUTH

RSET
250 ok
DEBUG SMTP: MessagingException while sending, THROW:
com.sun.mail.smtp.SMTPSendFailedException: 503 error: not authorized, use AUTH
;
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 503 error: not authorized, use AUTH

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at Mailer2.mailer2.main(mailer2.java:51)
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 503 error: not authorized, use AUTH

at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1616)
... 4 more
QUIT
221 bye
Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 503 error: not authorized, use AUTH
;
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 503 error: not authorized, use AUTH

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at Mailer2.mailer2.main(mailer2.java:51)
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 503 error: not authorized, use AUTH

at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1616)
... 4 more

最佳答案

缺少代码prop.put("mail.smtp.auth", "true");

根据提供商的不同,您可能还需要在邮件提交端口上请求 SSL 或 STARTLS。

关于java - 尝试使用JavaMail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24946163/

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