在Apache Netbeans上用java编写的sendmailcode只在开发计算机上工作。
String host = "smtp.xxxxx.com";
String Password = "xxxxxxxxxxxxxxxxxxxx";
String from = "xxxxx@xxxxx.com";
String toAddress = to;
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.host", host);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.trust", "*");
Session session = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, toAddress);
message.setSubject(sub);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(mes);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(name);
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
try {
Transport tr = session.getTransport("smtp");
tr.connect(host, from, Password);
tr.sendMessage(message, message.getAllRecipients());
System.out.println("Mail Sent Successfully");
tr.close();
} catch (SendFailedException sfe) {
System.out.println(sfe);
}
如果我用所有文件制作一个安装程序并将其安装在第二台计算机上,发送电子邮件将不起作用。
我怎样才能找到开发和其他计算机之间的区别?还是失败?
1条答案
按热度按时间6jjcrrmo1#
发现电子邮件发送问题。
我添加了以下属性:
耶