错误java.io.FileNotFoundException发送电子邮件RPGLE/java
我正在开发一个使用javax.mail的类,它只从我的AS400 RPGLE程序接收一些参数,并发送一封包含主题、正文和附件的电子邮件 在参数中,我传递服务器的路径(ex:'\\192.0.0.100\docs\new')和将要附加的文件的名称(ex:File.pdf),在本例中,它是一个.pdf文件。要读取服务器内部的文件,我将使用SmbFile通过域、用户和密码进行身份验证 我已经测试了几次代码,在我的eclipse中本地运行它,从我的主类调用方法传递硬编码的参数,它成功地发送了电子邮件,问题开始于我在生产环境中部署我的类时,我在发送消息时得到一个“javax.mail.MessagineException:IOException; 嵌套异常为:java.io.FileNotFoundException:\\192.0.0.100\docs\new\File.pdf(名称中的文件或目录不存在)。” 有趣的是,当程序调用错误java.io.FileNotFoundException发送电子邮件RPGLE/java,java,ibm-midrange,rpgle,rpg,Java,Ibm Midrange,Rpgle,Rpg,我正在开发一个使用javax.mail的类,它只从我的AS400 RPGLE程序接收一些参数,并发送一封包含主题、正文和附件的电子邮件 在参数中,我传递服务器的路径(ex:'\\192.0.0.100\docs\new')和将要附加的文件的名称(ex:File.pdf),在本例中,它是一个.pdf文件。要读取服务器内部的文件,我将使用SmbFile通过域、用户和密码进行身份验证 我已经测试了几次代码,在我的eclipse中本地运行它,从我的主类调用方法传递硬编码的参数,它成功地发送了电子邮件,问
Transport.send(message)时会出现错误
,在发送电子邮件之前,我放置了一个if(sFileReader.exists())
,它没有给出任何错误
我还放了一些日志来监视通过变量传递的值,它们都是正确的,与我在本地测试中使用的那些完全一样。在制作过程中也尝试过发送一封没有附件的电子邮件,效果很好
你们知道吗?非常感谢
下面是我的代码示例以及我如何在本地调用我的方法:
public static void main(String[] args) throws Exception {
sendEmail("192.0.0.100", "100", "user", "pwd", "test@email.com",
"test@email.com", "Subject", "Body", "smb://192.0.0.100/doc/new/", "File.PDF",
"domain", "user", "pwd");
}
public static void sendEmail(String server_ip, String server_port, final String username_mail, final String password_mail, String EMAIL_FROM, String list_emails, String subject, String body, String attachment_path, String attachment_name, String domain_attach, String user_attach, String password_attach) throws AddressException, MessagingException {
Session session = null;
Properties properties = null;
MimeMessage message = null;
MimeBodyPart attachmentBodyPart = null, textBodyPart = null;
Multipart multipart = null;
NtlmPasswordAuthentication auth_attach = null;
SmbFile sPathReader = null, sFileReader = null;
DataSource source = null;
properties = System.getProperties();
properties.setProperty("mail.smtp.host", server_ip);
properties.put("mail.smtp.port", server_port);
if(username_mail != "" && password_mail != "") {
Authenticator auth = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username_mail, password_mail);
}
};
session = Session.getInstance(properties, auth);
}else {
session = Session.getDefaultInstance(properties);
}
try {
// Authenticate to the server
auth_attach = new NtlmPasswordAuthentication(domain_attach, user_attach, password_attach);
sPathReader = new SmbFile(attachment_path, auth_attach);
sFileReader = new SmbFile(sPathReader, attachment_name);
if(sFileReader.exists()) {
message = new MimeMessage(session);
message.setFrom(new InternetAddress(EMAIL_FROM));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(list_emails));
message.setSubject(subject);
textBodyPart = new MimeBodyPart();
textBodyPart.setText(body);
attachmentBodyPart = new MimeBodyPart();
multipart = new MimeMultipart();
source = new FileDataSource(sFileReader.getUncPath());
attachmentBodyPart.setDataHandler(new DataHandler(source));
attachmentBodyPart.setFileName(attachment_name);
multipart.addBodyPart(textBodyPart);
multipart.addBodyPart(attachmentBodyPart);
message.setContent(multipart);
// Send message
Transport.send(message);
}
} catch (Exception e) {
e.printStackTrace();
}
}
我发现了这个问题,我的程序对于那些需要在windows中从服务器获取文件的程序来说是正确的,但是在我的例子中,我使用RPGLE程序从AS400调用我的类,它有一种不同的访问外部URL的方式,它需要路径中的“/QNTC/”,例如“/QNTC/192.0.0.100/docs/test.pdf”,不需要在Java中进行身份验证,IBM将这样做,因此在本例中,需要一个包含URL的简单字符串 关于如何在IFS下配置QNTC路径,IBM有很好的文档 我希望它能帮助别人