我在设置Outlook邮件到OutlookMail时遇到了麻烦,我按照这里和这里的说明进行操作
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", "smtp-mail.outlook.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.port", "587");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "true");
try
{
Authenticator auth = new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(d_email, d_password);
}
};
Session session = Session.getInstance(props, auth);
MimeMessage msg = new MimeMessage(session);
msg.setText("Hey, this is the testing email.");
msg.setSubject("Testing");
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("example@gmail.com"));
Transport.send(msg);
}catch (MessagingException mex) {
mex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我一直在收到错误:
javax.mail.MessagingException: Could not connect to SMTP host: …
Run Code Online (Sandbox Code Playgroud) 我正在使用PrimeFaces 5.3 <p:fileUpload>
上传PNG图像,我想<p:graphicImage>
在保存到数据库之前显示它的预览.
这是一个MCVE:
<h:form enctype="multipart/form-data">
<p:fileUpload value="#{bean.uploadedFile}" mode="simple" />
<p:graphicImage value="#{bean.image}" />
<p:commandButton action="#{bean.preview}" ajax="false" value="Preview" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
private UploadedFile uploadedFile;
public UploadedFile getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(UploadedFile uploadedFile) {
this.uploadedFile = uploadedFile;
}
public void preview() {
// NOOP for now.
}
public StreamedContent getImage() {
if (uploadedFile == null) {
return new DefaultStreamedContent();
} else {
return new DefaultStreamedContent(new ByteArrayInputStream(uploadedFile.getContents()), "image/png");
}
}
Run Code Online (Sandbox Code Playgroud)
在辅助bean上没有发生错误,图像将不会加载并显示在前端.客户端提到图像返回404未找到错误.