سؤال

باستخدام الرمز أدناه ، يمكنني إرسال بريد إلكتروني مكتوب باللغة غير الإنجليزية ، وعلى الرغم من أن الموضوع يظهر بشكل صحيح ، فإن الجسم يظهر على أنه رطالب.
أيه أفكار؟
شكرًا لك

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);

        }

لا يوجد حل صحيح

نصائح أخرى

محاولة:

msg.setContent(message, "text/plain; charset=UTF-8");

يحرر تغير إلى text/plain.

بدلاً من

msg.setContent(message, "text/plain");

أود أن أكتب

Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(message, "text/plain; charset=ISO-8859-7");
mp.addBodyPart(mbp);

msg.setContent(mp);

خمنت ISO-8859-7 من اسمك لأن هذا Charset مخصص لـ Greek ، ولكن ربما يمكنك اختياره بشكل صحيح. أو ربما أيضا UTF-8 يعمل لحالتك.

إذا لم يساعد أي شيء آخر ، فحاول تغيير ترميز ملفات المصدر الخاصة بك (بما في ذلك ملفات .java) إلى UTF8. في Eclipse ، يتم ذلك عبر Window -> التفضيلات -> عام -> مساحة العمل: ترميز ملف نصي كان لدي CP1252 كإعداد افتراضي لملفاتي النصية.

أحصل على نصي من ملفات .properties. تغييرها إلى UTF8 لم يساعد. هذا مجنون ، ولكن تبديل ملفات .java إلى UTF8 حل مشكلتي!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top