I had the same issue, but it is actually a very simple fix. All you have to do is change
message.setContent(schemeParsed, "text/html" ); //; charset=" + charset);
to
message.setText(schemeParsed, "utf-8", "html");
Then everything should work. If you think there might be an issue with your variable, here is all of my code.
import java.io.UnsupportedEncodingException;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class Drivers {
static Scanner scanly = new Scanner(System.in);
public static String username = "[email protected]";
public static String name = "";
public static String password = "your-password";
public static String recipient = "";
public static String subject = "";
public static String emessage = "";
public static String answer = "";
public static String count = "";
public static String wait = "";
public static boolean loop = true;
public static int countint;
public static int waitint;
public static void main(String[] args) throws UnsupportedEncodingException, InterruptedException {
print("Hi! Welcome! Please begin by entering the recipient: ");
recipient = scanly.nextLine();
print("What would you like your name to be?");
name = scanly.nextLine();
print("What would you like the subject line to be?");
subject = scanly.nextLine();
print("Please enter the message:");
emessage = scanly.nextLine();
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.mail.yahoo.com");
props.put("mail.smtp.port", "25");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
print("Recipient: " + recipient + "\nSubject: " + subject + "\nMessage: " + emessage);
while(loop)
{
print("Type 's' to send the message, 'c' to cancel, 'n' to change the message/subject, or 'sp' to choose how many.");
answer = scanly.nextLine();
if(answer.toLowerCase().equals("s"))
{
print("Establishing connection..");
MimeMessage message = new MimeMessage(session);
try {
print("Setting up defaults..");
message.setFrom(new InternetAddress(username, name));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));
message.setSubject(subject);
message.setText(emessage, "utf-8", "html");
print("Sending..");
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
print("Sent!");
print("Pausing..");
} else if(answer.toLowerCase().equals("c")) {
print("Bye!");
System.exit(0);
} else if(answer.toLowerCase().equals("n")) {
main(args);
} else if(answer.toLowerCase().equals("sp"))
{
print("How many times?");
count = scanly.nextLine();
countint = Integer.parseInt(count);
print("What would you like the wait time to be? (Recommended is 4000-10000)");
wait = scanly.nextLine();
waitint = Integer.parseInt(wait);
for (int i = 0; i < countint;
{
print("Establishing connection..");
Message message = new MimeMessage(session);
try {
print("Setting up defaults..");
message.setFrom(new InternetAddress(username, name));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));
message.setSubject(subject);
message.setText(emessage);
print("Sending..");
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
print("Sent!");
Thread.sleep(waitint);
}
} else
{
print("Error..");
}
}
}
public static void print(String ttp)
{
System.out.println(ttp);
}
}
Anyway, if there is any issue or anything, email me at [email protected]