Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3224968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:17:06+00:00 2026-05-17T16:17:06+00:00

I am using Spring MVC for my web application and I am using my

  • 0

I am using Spring MVC for my web application and I am using my applicationContext.xml
file to configure my emails which I am injecting into my controllers in my spring-servlet.xml file.

Some of the emails I need to send will need to be tailored to the customer that they are being sent to. Certain information in the email (First name, Last name, phone number,etc) will need to be filled in once the email text has been injected into controller and is being sent.

An example of this is is shown in the bean below

<bean id="customeMailMessage" class="org.springframework.mail.SimpleMailMessage">
   <property name="from" value="from@no-spam.com" />
   <property name="to" value="to@no-spam.com" />
   <property name="subject" value="Testing Subject" />
   <property name="text">
      <value>
         Dear %FIRST_NAME%

                 Blah Blah Blah Blah Blah...
                 We Understand that we can reach you at the following information

                 Phone:%PHONE%
                 Address:%ADDRESS%
      </value>
   </property>
</bean>

This would be a custom email message that I would define and inject into my controller. The code in my controller would then fill in the values based on the input collected from the customer so the controller would have code similar to the following

    //SimpleMailMessage property is injected into controller
    private SimpleMailMessage simpleMailMessage;

    //Getters and Setters for simpleMailMessage;


    MimeMessage message = mailSender.createMimeMessage();

   try{
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(simpleMailMessage.getFrom());
        helper.setTo(simpleMailMessage.getTo());
        helper.setSubject(simpleMailMessage.getSubject());

                String text = simpleMailMessage.getText();
                text.replace("%FIRST_NAME%",model.getFirstName());
                text.replace("%PHONE%",model.getPhone());
                text.replace("%ADDRESS%",model.getAddress());
        helper.setText(simpleMailMessage.getText());
     }
         catch (MessagingException e) {
    throw new MailParseException(e);
     }
     mailSender.send(message);**strong text**

The problem I am having is that when I try to replace the values such as %FIRST_NAME%,%PHONE% and %ADDRESS%>, it is not replacing it. I am not sure if this is because I am using replace() wrong, or if it is because it is treating it differently because the value is injected. I have also tried to use replaceAll() and that is not working either. If anybody has better ideas how to do this, please let me know.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:17:07+00:00Added an answer on May 17, 2026 at 4:17 pm

    Don’t forget that in Java Strings are immutable. i.e. you can’t change them, but rather create a new one from the old one (see the doc for replaceAll() and note the return value).

    So replace() won’t change the string that it’s called upon, but instead will return a new string with the replacement made. You can use the return value and so just chain these calls together:

    String newString = oldString.replace(..).replace(...);
    

    If you need to do a lot of this templating, you may be interested in Apache Velocity, or Freemarker. They are purpose-build templating engines that will do what you’re doing with many more options (e.g. providing looping, formatting, conditionals etc.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to integrate facebook login into my web application developed using Spring MVC.
I am using spring 3.1.2 MVC. I am trying to configure web application by
I'm creating a web application using spring mvc. I have started to incorporate the
So we're almost at our goal to test-drive our spring web-mvc application. We're using
I have configured in following way that spring MVC app using Spring 3.1.1.RELEASE web.xml
I am using Spring MVC for a web application and I am working with
I am building web application using Spring MVC Spring Security Hibenate MySQl I want
I am using Jboss and Netbeans to create Spring MVC web application on windows.
i'm creating a very simple (hello World quality) web application using spring mvc 3.0.
I am using spring security 3.0.5 in my web application based on Spring MVC.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.