我必须开发一个 java 应用程序。
在这里我得到以下错误:
Part 类型中的方法 setText(String) 不适用于参数 (String, String)
在这里,我必须通过 settext 将检索的用户名、检索密码发送到我的邮件。我如何在 settext 方法中调用上述 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("xxxxx@gmail.com","4242vfgDF!");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("krishnaveni.veeman@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("demo@gamil.com"));
message.setSubject("Testing Subject");
message.setText("Dear Friends This is your product name and price"+
retrievedPassword,retrievedUserName);
Transport.send(message);
System.out.println("Done");
}