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

  • Home
  • SEARCH
  • 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 4532590
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:02:58+00:00 2026-05-21T14:02:58+00:00

I send an account activation mail to my users using javamail. In that email,

  • 0

I send an account activation mail to my users using javamail. In that email, there is a link that when clicked, the user should activate their account, redirected to the main page of the application and get them logged in. How can i do that? Can i add a call a method call to a managed bean in that link i send as a HTML template?

This is the EJB i use for sending the email template:

@Stateless(name = "ejbs/EmailServiceEJB")
public class EmailServiceEJB implements IEmailServiceEJB {

    @Resource(name = "mail/myMailSession")
    private Session mailSession;

    public void sendAccountActivationLinkToBuyer(String destinationEmail,
            String name) {

        // Destination of the email
        String to = destinationEmail;
        String from = "dontreply2thismessage@gmail.com";

        try {
            Message message = new MimeMessage(mailSession);
            // From: is our service
            message.setFrom(new InternetAddress(from));
            // To: destination given
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(to));
            message.setSubject("Uspijesna registracija");
            // How to found at http://www.rgagnon.com/javadetails/java-0321.html
            message.setContent(generateActivationLinkTemplate(), "text/html");

            Date timeStamp = new Date();
            message.setSentDate(timeStamp);

            // Prepare a multipart HTML
            Multipart multipart = new MimeMultipart();
            // Prepare the HTML
            BodyPart htmlPart = new MimeBodyPart();
            htmlPart.setContent(generateActivationLinkTemplate(), "text/html");
            htmlPart.setDisposition(BodyPart.INLINE);

            // PREPARE THE IMAGE
            BodyPart imgPart = new MimeBodyPart();

            String fileName = "logoemailtemplate.png";

            ClassLoader classLoader = Thread.currentThread()
                    .getContextClassLoader();
            if (classLoader == null) {
                classLoader = this.getClass().getClassLoader();
                if (classLoader == null) {
                    System.out.println("IT IS NULL AGAIN!!!!");
                }
            }

            DataSource ds = new URLDataSource(classLoader.getResource(fileName));

            imgPart.setDataHandler(new DataHandler(ds));
            imgPart.setHeader("Content-ID", "<logoimg_cid>");
            imgPart.setDisposition(MimeBodyPart.INLINE);
            imgPart.setFileName("logomailtemplate.png");

            multipart.addBodyPart(htmlPart);
            multipart.addBodyPart(imgPart);
            // Set the message content!
            message.setContent(multipart);

            System.out.println("MIME!!!!");
            System.out.println(multipart.getContentType());

            Transport.send(message);

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }

    }    


    private String generateActivationLinkTemplate() {
        String htmlText = "";
        htmlText = "<table width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">  <tr>    <td><img src=\"cid:logoimg_cid\"/></td>  </tr>  <tr>    <td height=\"220\"> <p>Thanks for Joining Site.com</p>      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </p>    <p>Username:<br />      Password: </p>    <p>To confirm your email click <a href=\"#\">here</a>.</p></td>  </tr>  <tr>    <td height=\"50\" align=\"center\" valign=\"middle\" bgcolor=\"#CCCCCC\">www.site.com | contact@site.com | +38200 123 456</td>  </tr></table>";
        return htmlText;
    }


}

This is the EJB that will save in the session the user state(Log in):

public class AuthentificationEJB implements IAuthentificationEJB {

    @PersistenceContext
    private EntityManager em;

    // Login
    public boolean saveUserState(String email, String password) {
        // 1-Send query to database to see if that user exist
        Query query = em
                .createQuery("SELECT r FROM Role r WHERE r.email=:emailparam AND r.password=:passwordparam");
        query.setParameter("emailparam", email);
        query.setParameter("passwordparam", password);
        // 2-If the query returns the user(Role) object, store it somewhere in
        // the session
        List<Object> tmpList = query.getResultList();
        if (tmpList.isEmpty() == false) {
            Role role = (Role) tmpList.get(0);
            if (role != null && role.getEmail().equals(email)
                    && role.getPassword().equals(password)) {
                FacesContext.getCurrentInstance().getExternalContext()
                        .getSessionMap().put("userRole", role);
                // 3-return true if the user state was saved
                System.out.println(role.getEmail() + role.getPassword());
                return true;
            }
        }
        // 4-return false otherwise
        return false;
    }

Can I call the method saveUserState(email,password) from the template that i manually created in the method generateActivationLinkTemplate()? So the user gets redirected to the main page of the application and the user gets saved into the session

  • 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-21T14:02:59+00:00Added an answer on May 21, 2026 at 2:02 pm

    If you pass the activation key as request parameter in a link like as http://example.com/activate.xhtml?key=somelonganduniquekey, then just use @ManagedProperty to let JSF set the request parameter in the bean and do the validation and login job in the @PostConstruct.

    @ManagedBean
    @RequestScoped
    public class Activation {
    
        @ManagedProperty(value="#{param.key}")
        private String key;
    
        private boolean valid;
    
        @PostConstruct
        public void init() {
            // Get User based on activation key.
            // Delete activation key from database.
            // Login user.
        }
    
        // ...
    }
    

    with an activate.xhtml which look like this

    <h:head>
        <ui:fragment rendered="#{activation.valid}">
            <meta http-equiv="refresh" content="3;url=home.xhtml" />
        </ui:fragment>
    </h:head>
    <h:body>
        <h:panelGroup layout="block" rendered="#{activation.valid}">
            <p>Your account is successfully activated!</p>
            <p>You will in 3 seconds be redirected to <h:link outcome="home">home page</h:link></p>
        </h:panelGroup>
        <h:panelGroup layout="block" rendered="#{!activation.valid}">
            <p>Activation failed! Please enter your email address to try once again.</p> 
            <h:form>
                ...
            </h:form>
        </h:panelGroup>
    </h:body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a confirmation link method to activation of user account in my website.when
I send out html email on user activation with token that I encode with
How can I send email using Perl through my Gmail account? The one CPAN
I am trying to send an e-mail using gmail account (Delphi 7, Indy 10)
For testing purposes I want send mail to my localhost user account rather than
I use mstmp to send mail from various smtp account. Using PHP's mail command
Is it possible to login to my gmail account and send mail using curl
I send a mail which includes activation link. When i open the program ,
Trying to send an activation email for newly registered users, here's the code so
How to send activation email with username by using django-registration .I've configured Amazon SES

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.