我正在尝试通过我的网站(JSF 网站)发送电子邮件,该网站部署在 apache 服务器上,但我不断收到“连接被拒绝:连接”消息,但是如果我直接从 NetBeans 运行 Java 应用程序中的代码,则代码可以完美运行。抱歉,如果我在帖子中犯了一些错误,你可以说这是我第一次发帖。:)
public void sendReplicationCheckResult() {
String to = "JcbSupportingSystem@jcbank.com.jo";
// Sender's email ID needs to be mentioned
String from = "Palestine.IT@jcbank.com.jo";
// Assuming you are sending email from localhost
String host = "192.168.52.95";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host", host);
properties.put("mail.smtp.auth", "false");
properties.setProperty("mail.smtp.port", "25");
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
try {
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
// Set Subject: header field
message.setSubject("Replication Check Results");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(message, "text/html");
// Create a multipart message
Multipart multipart = new MimeMultipart();
// Set text message part
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
String filename = "C:\\Temp\\ReplicationCheck.pdf";
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
墨色风雨
汪汪一只猫
相关分类