这是控制器
类JavaMailerController {
JavaMailerService javamailerservice def = {javamailerservice.serviceMethod()} }
这是我们的服务
import javax.mail.;import javax.mail.internet.;import java.util.
类JavaMailerService {
布尔事务= false def serviceMethod() { String d_email = "thisemail@gmail.com",d_password =“this d_password”,d_host = "smtp.gmail.com",d_port = "587",m_to = "thisto@gmail.com",m_subject =“the”,m_text =“嗨,这是测试邮件。”;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");//pros.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安全= System.getSecurityManager();尝试{ Authenticator =新SMTPAuthenticator();会话会话= Session.getInstance(props,auth);//session.setDebug(真);MimeMessage msg =新MimeMessage(会话);msg.setText(m_text);msg.setSubject(m_subject);msg.setFrom(新InternetAddress(d_email));msg.addRecipient(Message.RecipientType.TO,Message.RecipientType.TO)
新InternetAddress(M_to);Transport.send(msg);} catch (异常mex) { mex.printStackTrace();}}
}
私有类SMTPAuthenticator扩展javax.mail.Authenticator { public PasswordAuthentication getPasswordAuthentication() {返回新PasswordAuthentication(d_email,d_password);}
误差
错误200: java.lang.NullPointerException:无法在空对象Servlet上调用方法serviceMethod():grails :/javaMailer/grails/javaMailer/x.分派异常消息:不能对null对象调用方法serviceMethod(),原因是: java.lang.NullPointerException:不能调用null对象类上的方法serviceMethod():在Line:-1代码段中未知:
发布于 2009-01-26 04:05:11
我认为您没有在控制器中camelCase您的服务字段。
class JavaMailerController {
JavaMailerService javaMailerService
def x = {
javaMailerService.serviceMethod()
}
}https://stackoverflow.com/questions/477863
复制相似问题