我想用非英語電子郵件ID(例如डेमो@डेमो.कॉम)將電子郵件發送到使用java的任何電子郵件ID 。如何用Java中的非英文發件人ID發送電子郵件?
當我使用:
String to = "[email protected]";
String from = "डेमो@डेमो.कॉम";
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try{
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("This is the Subject Line!");
// Now set the actual message
message.setText("This is actual message");
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
它拋出異常,如:
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: 501 Syntax error in parameters or arguments
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at com.data.TestingSendMail.main(TestingSendMail.java:49)
請建議我什麼,我需要爲它做。
嘗試'message.setHeader(「Content-Type的「,」text/plain; charset = UTF-8「);' – silentprogrammer
@singhakash它不能工作 – GeekOnJava