问题描述
- web项目中页面修改javamail发件人信息后发邮件失败
- 我们的web项目使用javamail发送邮件。页面可修改发送邮件的服务器、发件人信息,但是现在在页面修改发件人邮箱地址和密码之后,发送邮件失败。重起Tomcat服务器之后,又可以正常发送邮件,各位大神,有谁知道为什么呢?
public boolean sendMail(String subject String body){ Properties props = new Properties(); props.put(""mail.smtp.host"" server); props.put(""mail.smtp.auth"" needAuth); props.put(""mail.smtp.sender"" sender); props.put(""mail.smtp.password"" password); // 判断是否需要身份认证 MailAuthenticator authenticator = null; if (needAuth) { authenticator = new MailAuthenticator(sender password); } try { Session session = Session.getDefaultInstance(props authenticator); MimeMessage message = new MimeMessage(session); InternetAddress from = null; if(null != sender && !"""".equals(sender)){ from = new InternetAddress(sender); } message.setFrom(from); String[] str = to.split(""); InternetAddress[] address = new InternetAddress[str.length]; for (int i = 0; i < str.length; i++) { address[i] = new InternetAddress(str[i]); } message.setRecipients(Message.RecipientType.TOaddress); message.setSubject(subjectUTF-8""); message.setSentDate(new Date()); MimeBodyPart mbp = new MimeBodyPart(); mbp.setContent(bodytext/html;charset=UTF-8""); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(mbp); message.setContent(multipart); Transport.send(message); return true; } catch (Exception e) { return false; }
修改发件人之后,报如下异常:
com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid User 684966a9-37c9-4b09-ba32-ea282cf46b58
;
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 550 Invalid User 684966a9-37c9-4b09-ba32-ea282cf46b58at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2057)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1580)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1097)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:146)
解决方案
是不是tomcat缓存的问题
时间: 2024-10-12 17:35:34