简体   繁体   中英

Sending message through java mail

Hello i am able to send a mail from my web application. But the problem here is am able to send only one line of message ie

I want to send a message saying:

Your username is : xxxx Your PassWord is: xxx

     Message message = new MimeMessage(session);
                    message.setFrom(new InternetAddress("xxx@gmail.com"));
                    message.setRecipients(Message.RecipientType.TO,
                        InternetAddress.parse(Class.email));
                    message.setSubject("Registration Confirmation with SK Business Group");
                    message.setContent("<h1>Congratulations on successfully registering with us</h1><h2>Your user name is:</h2>" +Class.uname ,  
                            "text/html");
message.setContent("<h2>Your password is:</h2>" +Class.pass ,  
                            "text/html");

                    Transport.send(message);

But when the mail reaches the recipient only username is displayed...

I want both username and password to be displayed. Some one please help me resolving this..Thanks in advance.

Note : Uname and pass are static variables of a class which is got by its classname.

You are setting the content twice, add both lines in the same call to setContent :

message.setContent("<h1>Congratulations on successfully registering with us</h1>"
    + "<h2>Your user name is:</h2>" +ApproveDAO.uname
    + "<h2>Your password is:</h2>" +ApproveDAO.pass, "text/html");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM