次のコードを使用してメールを送信しています。
protected void mailSettings() {
Object lookedUp = null;
String mailSettingValues[] = null;
try {
InitialContext initialContext = new InitialContext();
lookedUp = initialContext.lookup("java:/comp/env/mailsettings");
mailSettingValues = lookedUp.toString().split(",");
smtphost = mailSettingValues[0];
port = mailSettingValues[1];
username = mailSettingValues[2];
password = mailSettingValues[3];
} catch (NamingException e) {
e.printStackTrace();
}
m_properties = new Properties();
m_properties.put("mail.smtp.host", smtphost);
m_properties.put("mail.smtp.auth", "true");
m_properties.put("mail.smtp.starttls.enable", "true");
m_properties.put("mail.smtp.port", port);
m_Session = Session.getDefaultInstance(m_properties,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
public void sendMail(String mail_from, String mail_to, String mail_subject,
String m_body) {
try {
m_simpleMessage = new MimeMessage(m_Session);
m_fromAddress = new InternetAddress(mail_from);
m_toAddress = new InternetAddress(mail_to);
m_simpleMessage.setFrom(m_fromAddress);
m_simpleMessage.setRecipient(RecipientType.TO, m_toAddress);
m_simpleMessage.setSubject(mail_subject);
m_simpleMessage.setContent(m_body, "text/plain");
Transport.send(m_simpleMessage);
} catch (MessagingException ex) {
ex.printStackTrace();
}
}
to_email
このコードの時点で、アドレスからの電子メールとそのパスワードが必要ですが、認証(ユーザーパスワードの取得)なしでアドレスにメールを送信したいと思います。
これはどのように行うことができますか?
私は次のことをする必要があります:
- プロパティまたはコンテキストファイルから差出人アドレスを取得します
- プロパティまたはコンテキストファイルから宛先アドレスを取得します
to_address
差出人アドレスを認証せずににメールを送信する