导入javax.mail。
进口
javax.mail.internet。
进口
Java.UTI.*;
类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”,
DyPART);
props.put(“mail.smtp.socketfactory.class”,
“javax.net.ssl.sslsocketfactory”);
props.put(“mail.smtp.socketfactory.fallback”,
“假”;
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,
新的国际地址(m_to);
发送(msg);
}
catch(异常mex)
{
mex.printstacktrace();
}
}
}
私有类smtpauthenticator
扩展javax.mail.authenticator
{
公共密码身份验证GetPasswordAuthentication()
{
返回新密码身份验证(D_电子邮件,
DY密码;
}
}
错误200:java.lang.NullPointerException:无法对空对象调用方法serviceMethod()
servlet:grails
uri:/javamailer/grails/javamailer/x.dispatch
异常消息:无法对空对象调用方法ServiceMethod()
原因:java.lang.nullPointerException:无法对空对象调用方法serviceMethod()
类别:未知
行:[-1]
代码段: