问题描述
我有一个HTML代码,其中包含指向屏幕截图的链接。当我使用Java代码从远程计算机以电子邮件形式发送此HTML文件作为附件(外观)时,附件已成功发送。但是,当我单击屏幕快照链接(从本地计算机打开的附件邮件)时,我在浏览器中收到“找不到文件”消息。我在HTML文件中尝试了以下不同代码,但没有一个能够打开屏幕截图。
HTML文件位置(在远程计算机中-192.145.6.5):
c:\Java Code\Practice\Report.html
屏幕截图位置(在远程计算机上-192.145.6.5):
c:\Java Code\Practice\Screenshot\MyPics.png
Screenshot<a href="file:///Java Code\Practice\Screenshot\MyPics.png">
Screenshot<a href="file:///c:\Java Code\Practice\Screenshot\MyPics.png">
Screenshot<a href="file:/c:\Java Code\Practice\Screenshot\MyPics.png">
Screenshot<a href="\\192.145.6.5\Java Code\Practice\Screenshot\MyPics.png">
Screenshot<a href="file:/192.145.6.5\c:\Java Code\Practice\Screenshot\MyPics.png">
Screenshot<a href="file:///192.145.6.5\c:\Java Code\Practice\Screenshot\MyPics.png">
public class SendingEmail {
public static void main(String[] args) throws IOException {
File mailReportFolder = new File("Mail Report");
File fileClientResult = new File(mailReportFolder.getAbsolutePath() + "\\Email Report.txt");
String clientTextPath = fileClientResult.getAbsolutePath().replaceAll("\\\\","/");
String emailBodyText = new String(Files.readAllBytes(Paths.get(clientTextPath)));
final String username = "[email protected]";
final String password = "Password123";
String fromEmail = "[email protected]";
String toEmail = "[email protected]";
Properties properties = new Properties();
properties.put("mail.smtp.auth","true");
properties.put("mail.smtp.starttls.enable","true");
properties.put("mail.debug","true");
properties.put("mail.smtp.host","192.145.40.56");
// set the port of SMTP server
properties.put("mail.smtp.port","25");
Session session = Session.getInstance(properties,new javax.mail.Authenticator() {
protected PasswordAuthentication getpasswordAuthentication() {
return new PasswordAuthentication(username,password);
}
});
MimeMessage msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(fromEmail));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(toEmail));
msg.setSubject("Report Checking");
BodyPart messageBodyPart = new MimeBodyPart();
StringBuilder sb = new StringBuilder();
sb.append(emailBodyText);
String message = sb.toString();
messageBodyPart.setContent(message,"text/html");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
String fileName = "C:\\Java Code\\Practice\\Report.html";
DataSource source = new FileDataSource(fileName);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(fileName);
multipart.addBodyPart(messageBodyPart);
msg.setContent(multipart);
Transport.send(msg);
System.out.println("Message Sent");
} catch (MessagingException e) {
e.printstacktrace();
}
}
}
请告知我是否需要从头到尾进行任何处理。谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)