[英]method setText(String) in the type Part is not applicable for the arguments
I have to develop one java application. 我必须开发一个Java应用程序。
Here i got the below error: 在这里我得到以下错误:
The method setText(String) in the type Part is not applicable for the arguments (String, String) 部分类型中的方法setText(String)不适用于参数(字符串,字符串)
Here i have to send the retrievedUserName,retrievedPassword to my mail via settext. 在这里,我必须通过settext将retrevedUserName,retrievedPassword发送到我的邮件中。 How can i call the above 2 string value in settext method.please help me.whats wrong in my code. 我该如何在settext方法中调用上述2个字符串值。请帮助我。我的代码有什么错误。
This is my code: 这是我的代码:
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");
}
Try specifying the charset. 尝试指定字符集。 I also use setContent, but I suppose setText would work the same way. 我也使用setContent,但是我想setText将以相同的方式工作。 Try replacing your setText call with this: 尝试将您的setText调用替换为:
message.setContent("Dear Friends This is your product name and price "+
retrievedPassword+retrievedUserName, "text/html; charset=utf-8");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.