当我使用javamail api从我的雅虎地址发送邮件时,他们不会转到发送文件夹。有什么问题?这是我的源代码:
public void doSendYahooMail(){
from = txtFrom.getText();
password= new String(txtPassword.getPassword());
to = txtTo.getText();
subject = txtSubject.getText();
email_body = jTextArea1.getText();
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.mail.yahoo.com");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Session session = Session.getInstance(props,
new javax.mail.Authenticator(){
@Override
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(from, password);
}
}
);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
message.setSubject(subject);
message.setText(email_body);
Transport.send(message);
JOptionPane.showMessageDialog(this, "Message Sent!","Sent",JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.toString());
}
}
我需要进行哪些修改
答案 0 :(得分:0)
如果您想在已发送消息文件夹中找到副本,则需要自己将其放在那里。有关示例,请参阅JavaMail sample program msgsend.java。
此外,您还要在程序中修复这些common JavaMail mistakes。