Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails Error for using e-mail service
    text
    copied!<p>This is the controller </p> <blockquote> <p>class JavaMailerController {</p> <pre><code>JavaMailerService javamailerservice def x = {javamailerservice.serviceMethod()} } </code></pre> </blockquote> <p>This is the Service </p> <blockquote> <p>import javax.mail.<em>; import javax.mail.internet.</em>; import java.util.*;</p> <p>class JavaMailerService {</p> <pre><code>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"); </code></pre> <p>// just in case, but not currently necessary, oddly enough 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");</p> <pre><code> 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, </code></pre> <p>new InternetAddress(m_to)); Transport.send(msg); } catch (Exception mex) { mex.printStackTrace(); } }</p> <p>}</p> <p>private class SMTPAuthenticator extends javax.mail.Authenticator { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(d_email, d_password); } }</p> </blockquote> <p>The Error</p> <p>Error 200: java.lang.NullPointerException: Cannot invoke method serviceMethod() on null object Servlet: grails URI: /JavaMailer/grails/javaMailer/x.dispatch Exception Message: Cannot invoke method serviceMethod() on null object Caused by: java.lang.NullPointerException: Cannot invoke method serviceMethod() on null object Class: Unknown At Line: [-1] Code Snippet:</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload