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 6346743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:04:36+00:00 2026-05-24T21:04:36+00:00

I’m trying to send a mail from my jsf page. this is my method:

  • 0

I’m trying to send a mail from my jsf page. this is my method:

public String voegGroepToe()
{
    String resultaat = "overzichtGroepEnProject";
    if(project.getGroepen().size()<project.getMaxAantalGroepen())        
        project.voegGroepToe(groep);

    for(Student s : groep.getStudenten())
    {

    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.live.com");
    props.put("mail.smtp.port", "587");

    Session mailSession = Session.getDefaultInstance(props);
    Message simpleMessage = new MimeMessage(mailSession);

    InternetAddress fromAddress = null;
    InternetAddress toAddress = null;
    try {
        fromAddress = new InternetAddress(from);
        toAddress = new InternetAddress(s.getEmail());
    } catch (AddressException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        simpleMessage.setFrom(fromAddress);
        simpleMessage.setRecipient(RecipientType.TO, toAddress);
        simpleMessage.setSubject(subject);
        simpleMessage.setText(message);

        Transport.send(simpleMessage);          
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }

    return resultaat;
}

resultaat is the jsf page where the application should go to after it sended the emails.
groep means a group with students. the mail should be sent to every student of the group.
the from = “myownemailadress@hotmail.com”

But this isn’t working and it doesn’t give an errormessage, it looks like it get stuck at Transport.send… What am i doing wrong?

  • 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-24T21:04:37+00:00Added an answer on May 24, 2026 at 9:04 pm

    You would rather like to connect only once before the loop and then send every message using Transport#sendMessage() inside the loop and then close the connection after the loop. The second problem is that you don’t seem to pass in the username/password anywhere.

    Here’s how you should do it:

    String host = "smtp.live.com";
    int port = 587;
    String username = "you@live.com";
    String password = "yourpassword";
    
    Properties props = new Properties();
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", String.valueOf(port));
    Session mailSession = Session.getDefaultInstance(props);
    Transport transport = null;
    
    try {
        transport = mailSession.getTransport("smtp");
        transport.connect(host, username, password);
        InternetAddress fromAddress = new InternetAddress(from);
    
        for (Student s : groep.getStudenten()) {
            InternetAddress[] toAddresses = { new InternetAddress(s.getEmail()) };
            Message simpleMessage = new MimeMessage(mailSession);
            simpleMessage.setFrom(fromAddress);
            simpleMessage.setRecipients(RecipientType.TO, toAddresses);
            simpleMessage.setSubject(subject);
            simpleMessage.setText(message);
            simpleMessage.setSentDate(new Date()); // Otherwise you end up in junk.
            simpleMessage.saveChanges(); // Transport#sendMessage() doesn't do it.
            transport.sendMessage(simpleMessage, toAddresses);
        }
    } catch (MessagingException e) {
        // Handle it! Display a FacesMessage or something.
    } finally {
        if (transport != null) try { transport.close(); } catch (MessagingException ignore) {}
    }
    

    (I don’t guarantee that it will work this way, I don’t have experience with Live.com SMTP servers, perhaps you need an additional Authenticator)

    As a completely different alternative, you could also send a single message to groupname@yourdomain.com with all those recipients as BCC.

    See also:

    • JavaMail Fundamentals – Transport

    Please note that this problem is completely unrelated to JSF. You would have exactly the same problem when doing so in a plain vanilla Java class with a main() method.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.