このJavaクラスを使用してLinode Serverから電子メールを送信しています。好奇心旺盛なことは、私は自分のアカウント[email protected]でメールを受信しますが[email protected]mail smtp host with Java
String from = "[email protected]";
// Assuming you are sending email from localhost
String host = "localhost";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host", host);
// 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("Alert from LINODE");
// Now set the actual message
message.setText(msg);
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
に私は
public class MailClient {
protected static final Logger looger = LoggerFactory.getLogger(MailClient.class);
@Autowired
private JavaMailSender mailSender;
private MailContentBuilder mailContentBuilder;
@Autowired
public MailClient(JavaMailSender mailSender, MailContentBuilder mailContentBuilder) {
this.mailSender = mailSender;
this.mailContentBuilder = mailContentBuilder;
}
//TODO: in a properties
public void prepareAndSend(String recipient, String message) {
MimeMessagePreparator messagePreparator = mimeMessage -> {
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage);
messageHelper.setFrom("[email protected]");
messageHelper.setTo(recipient);
messageHelper.setSubject("Sample mail subject");
String content = mailContentBuilder.build(message);
messageHelper.setText(content, true);
};
try {
if (looger.isDebugEnabled()) {
looger.debug("sending email to " + recipient);
}
mailSender.send(messagePreparator);
} catch (MailException e) {
looger.error(e.getMessage());
}
}
}
にそれを変更しました。しかし、私は同じを持っていないということです問題
なぜそれが好奇心ですか? – azurefrog