これがコントローラー
クラス JavaMailerController {
JavaMailerService javamailerservice def x = {javamailerservice.serviceMethod()} }
これがサービスです
javax.mail をインポートします。; javax.mail.internet をインポートします。; import java.util.*;
クラス JavaMailerService {
boolean transactional = false def serviceMethod() { String d_email = "thisemail@gmail.com", d_password = "thispassword", d_host = "smtp.gmail.com", d_port = "587", m_to = "thisto@gmail.com", m_subject = "Testing", m_text = "Hey, this is the testing email."; Properties props = new Properties(); props.put("mail.smtp.user", d_email); props.put("mail.smtp.host", d_host); props.put("mail.smtp.port", d_port); props.put("mail.smtp.starttls.enable","true");
// 念のためですが、現在は必要ありません。奇妙なことに十分な props.put("mail.smtp.auth", "true"); //props.put("mail.smtp.debug", "true"); props.put("mail.smtp.socketFactory.port", d_port); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager(); try { Authenticator auth = new SMTPAuthenticator(); Session session = Session.getInstance(props, auth); //session.setDebug(true); MimeMessage msg = new MimeMessage(session); msg.setText(m_text); msg.setSubject(m_subject); msg.setFrom(new InternetAddress(d_email)); msg.addRecipient(Message.RecipientType.TO,
新しい InternetAddress(m_to)); Transport.send(メッセージ); } catch (例外 mex) { mex.printStackTrace(); } }
}
プライベート クラス SMTPAuthenticator extends javax.mail.Authenticator { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(d_email, d_password); } }
エラー
エラー 200: java.lang.NullPointerException: null オブジェクトでメソッド serviceMethod() を呼び出せません サーブレット: grails URI: /JavaMailer/grails/javaMailer/x.dispatch 例外メッセージ: null オブジェクトでメソッド serviceMethod() を呼び出せません 原因: java. lang.NullPointerException: null オブジェクトでメソッド serviceMethod() を呼び出せません クラス: 不明 行: [-1] コード スニペット: