Announcement Announcement Module
Collapse
No announcement yet.
MailPreparationException when Sending Velocity-based E-mail with Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MailPreparationException when Sending Velocity-based E-mail with Spring

    Hi,
    I'm working with spring integration and velocity to create my email template and send the email to a smtp server.
    In my configuration file I made a transformer to prepare the email and i used an outbound-channel-adapter to send the email.
    when i ran my project i encountered the following exception
    Quote:
    org.springframework.mail.MailPreparationException: Could not prepare mail; nested exception is java.lang.NullPointerException
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:368)
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:345)
    at com.example.TemplateSender.send(TemplateSender.jav a:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.expression.spel.support.Reflec tiveMethodExecutor.execute(ReflectiveMethodExecuto r.java:58)
    at org.springframework.expression.spel.ast.MethodRefe rence.getValueInternal(MethodReference.java:76)
    at org.springframework.expression.spel.ast.CompoundEx pression.getValueInternal(CompoundExpression.java: 57)
    at org.springframework.expression.spel.ast.SpelNodeIm pl.getValue(SpelNodeImpl.java:93)
    at org.springframework.expression.spel.standard.SpelE xpression.getValue(SpelExpression.java:93)
    at org.springframework.integration.handler.AbstractMe ssageProcessor.evaluateExpression(AbstractMessageP rocessor.java:48)
    at org.springframework.integration.handler.MethodInvo kingMessageProcessor.processMessage(MethodInvoking MessageProcessor.java:162)
    ... 37 more
    Caused by: java.lang.NullPointerException
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTr ansport.java:557)
    at org.springframework.mail.javamail.JavaMailSenderIm pl.doSend(JavaMailSenderImpl.java:402)
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:341)
    at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:356)
    ... 50 more
    and this is a part of my code

    configuration file
    ****************************************
    <transformer input-channel="channelA" output-channel="aftervelocitytransformerChannel">
    <beans:bean class="com.example.ToEmailTransformer" >
    <beansroperty name="velocityEngine" ref="velocityEngine"></beansroperty>
    </beans:bean>
    </transformer>

    <outbound-channel-adapter

    channel="aftervelocitytransformerChannel"
    ref="templatesender"
    method="send">
    </outbound-channel-adapter>
    ****************************************
    ToEmailTransformer.java
    Quote:
    public class ToEmailTransformer {

    private VelocityEngine velocityEngine;

    @Transformer
    public MimeMessagePreparator transform ( final Message<Notification> mesg){
    MimeMessagePreparator preparator = new MimeMessagePreparator(){
    @SuppressWarnings("unchecked")
    public void prepare(MimeMessage mimeMessage) throws Exception {
    MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
    Map model = new HashMap();
    model.put("notification", (Notification)mesg.getPayload());
    String text = VelocityEngineUtils
    .mergeTemplateIntoString(velocityEngine, "com/example/fr.html", model);
    System.out.println(text);
    message.setText(text, true);
    }
    };
    return preparator;
    }

    public void setVelocityEngine(VelocityEngine velocityEngine) {
    this.velocityEngine = velocityEngine;
    }
    TemplateSender.java
    Quote:
    public class TemplateSender {

    private JavaMailSender mailSender;

    public void setMailSender(JavaMailSender mailsender) {
    this.mailSender = mailsender;
    }

    public void send(MimeMessagePreparator preparator){

    this.mailSender.send(preparator);

    }
    }
    I will appreciate your help and time
Working...
X