I have to develop one java application.
Here i got the below error:
The method setText(String) in the type Part is not applicable for the arguments (String, String)
Here i have to send the retrievedUserName,retrievedPassword to my mail via settext.
How can i call the above 2 string value in settext method.please help me.whats wrong in my code.
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. Try replacing your setText call with this: