1
我必须开发一个Java应用程序。类型Part中的方法setText(String)不适用于参数
在这里,我得到了以下错误:
在型部件的制备方法的setText(字符串)不适用的参数(字符串,字符串)
在这里,我要送retrievedUserName, retrievePassword通过settext传递给我的邮件。 如何在settext method.please中调用上述2字符串值帮助我。在我的代码中出现错误。
这是我的代码:
public class SendMail {
public String authentication(String Product,String Cost){
String retrievedUserName = "";
String retrievedPassword = "";
String retrievedEmail = "";
String status = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
PreparedStatement statement = con.prepareStatement("SELECT xcart_products.product,xcart_products.list_price,xcart_customers.email FROM xcart_products,xcart_customers WHERE product = '"+Product+"'");
ResultSet result = statement.executeQuery();
while(result.next()){
retrievedUserName = result.getString("list_price");
retrievedPassword = result.getString("product");
retrievedEmail = result.getString("email");
}
if(retrievedPassword.equals(Product)){
status = "The product name is send to your email";
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
new PasswordAuthentication("[email protected]","4242vfgDF!");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
message.setSubject("Testing Subject");
message.setText("Dear Friends This is your product name and price"+
retrievedPassword,retrievedUserName);
Transport.send(message);
System.out.println("Done");
}
感谢danL.it是为我工作。 – android
没问题,很乐意帮忙。如果你不介意对我的答案进行投票,我将不胜感激。感谢你的接纳! – SISYN
在使用setContent()时,不会产生“\ n”的效果。我必须需要fistline retrievePassword,必须需要第二行retrieveUserName.so我已经使用了下面的代码。但它对我来说不起作用。 message.setContent(“这是你的产品名称”+ retrievedPassword +“\ nThis is your price”+ retrieveUserName,“text/html; charset = utf-8”); – android