codifica elettronica Java caratteri non inglesi
-
23-09-2019 - |
Domanda
usando il codice seguente posso inviare una e-mail scritta in non-inglese e anche se il soggetto appare correttamente il corpo appare come senza senso.
Qualsiasi idee?
Grazie
public void postMail(String recipient, String subject, String message, String from) throws MessagingException, UnsupportedEncodingException {
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "mail.infodim.gr");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress addressTo=new InternetAddress(recipient);
msg.setRecipient(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
Nessuna soluzione corretta
Altri suggerimenti
Prova:
msg.setContent(message, "text/plain; charset=UTF-8");
Modifica Cambiato in text/plain
.
Al posto di
msg.setContent(message, "text/plain");
Vorrei scrivere
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(message, "text/plain; charset=ISO-8859-7");
mp.addBodyPart(mbp);
msg.setContent(mp);
ho indovinato ISO-8859-7
dal tuo nome, perché questo charset è per il greco, ma forse è possibile scegliere più correttamente. O forse UTF-8
anche opere per il vostro caso.
Se non aiuta altro, provare a cambiare una codifica dei file di origine (inclusi i file .java) per UTF8. In Eclipse è fatto tramite Finestra -> Preferenze -> Generali -> Area di lavoro: codifica del file di testo Ho avuto CP1252 come predefinito per i miei file di testo.
sto ottenendo il mio testo da file .properties. cambiarli a UTF8 non ha aiutato. Questo è folle, ma il passaggio i miei file .java al UTF8 risolto il mio problema!