您好,我可以从我的网络应用程序发送邮件。但这里的问题是我只能发送一行消息,即
我想发送一条消息:
您的用户名是:xxxx 您的密码是:xxx
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="245c5c5c644349454d480a474b49" rel="noreferrer noopener nofollow">[email protected]</a>"));
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);
但是当邮件到达收件人时,仅显示用户名...
我希望同时显示用户名和密码。请有人帮我解决这个问题..先谢谢了。
注意: uname和pass是类的静态变量,通过类名获取。
最佳答案
您要设置内容两次,请在对 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");
关于java - 通过java邮件发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23260313/