我正在尝试使用Java邮件。这适用于Gmail,但当我尝试通过雅虎或热门邮件发送它显示
com.sun.mail.smtp.SMTPSendFailedException: 553 From address not verified
我用过
mailHost = "smtp.mail.yahoo.com";
和port = 465"
任何机构都可以告诉我如何解决这个问题。提前谢谢。
这里我发送代码
public MailSender(String userId, String password)
{
this.userId = userId;
this.password = password;
Properties properties = new Properties();
properties.setProperty("mail.transport.protocol", "smtp");
properties.setProperty("mail.host", mailHost);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "465");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.socketFactory.fallback", "false");
properties.setProperty("mail.smtp.quitwait", "false");
session = Session.getDefaultInstance(properties, this);
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(userId, password);
}
public synchronized void sendMail(String subject, String body, String sender, String reciever) throws AddressException, MessagingException
{
MimeMessage mimeMessage = new MimeMessage(session);
DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
mimeMessage.setSender(new InternetAddress(sender));
mimeMessage.setSubject(subject);
mimeMessage.setDataHandler(dataHandler);
if(reciever.indexOf(",")>0)
{
mimeMessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(reciever));
}
else
{
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(reciever));
}
Transport.send(mimeMessage);
}
答案 0 :(得分:2)
此错误消息的最可能原因是您必须先登录SMTP服务器,然后才能通过它发送任何消息。或者,可能是因为您尝试从非雅虎邮箱地址或不存在的邮件地址发送。
答案 1 :(得分:1)
mailHost =“smtp.mail.yahoo.com”;
和port = 587
试试这个
答案 2 :(得分:1)
尝试使用以下设置:
Server: smtp.mail.yahoo.com
Port: 465
Security: SSL