A
Andee Weir
Hi everyone,
Thanks for taking the time to look at this.
I've got a problem trying to send emails with 'unusual' characters
(e.g. ó) in the Subject (& contents). The following code gives an
example :-
package mail;
import javax.mail.*;
import java.util.*;
import javax.mail.internet.*;
public class Send {
static String mailServer = "smtp.server.com";
static String mailFrom = "(e-mail address removed)";
static String mailTo = "(e-mail address removed)";
static String mailSubject = "Actualización";
static String mailBody = "Actualización";
static Properties props = System.getProperties();
public static void Send() {
props.put("mail.host",mailServer);
props.put("mail.transport.protocol","smtp");
Session mailSession = Session.getDefaultInstance(props,null);
mailSession.setDebug(false);
MimeMessage msg = new MimeMessage(mailSession);
try {
msg.setFrom(new InternetAddress(mailFrom));
InternetAddress[] address = {new InternetAddress(mailTo)};
msg.setRecipients(Message.RecipientType.TO,address);
msg.setSubject(mailSubject, "UTF8");
msg.setSentDate(new Date());
msg.setText(mailBody, "UTF8");
Transport.send(msg);
} catch (Exception e) {
}
}
public static void main(String[] args) {
Send();
}
}
When I run this I end up with '=?UTF8?Q?Actualizaci=C3=B3n?=' in the
subject & the contents of 'This message uses a character set that is
not supported by the Internet Service. To view the original message
content, open the attached message. If the text doesn't display
correctly, save the attachment to disk, and then open it using a
viewer that can display the original character set.'.
The email server can deal with these special characters as I can use
Outlook to create the email I require.
Thanks in advance for any solutions.
Andee
Thanks for taking the time to look at this.
I've got a problem trying to send emails with 'unusual' characters
(e.g. ó) in the Subject (& contents). The following code gives an
example :-
package mail;
import javax.mail.*;
import java.util.*;
import javax.mail.internet.*;
public class Send {
static String mailServer = "smtp.server.com";
static String mailFrom = "(e-mail address removed)";
static String mailTo = "(e-mail address removed)";
static String mailSubject = "Actualización";
static String mailBody = "Actualización";
static Properties props = System.getProperties();
public static void Send() {
props.put("mail.host",mailServer);
props.put("mail.transport.protocol","smtp");
Session mailSession = Session.getDefaultInstance(props,null);
mailSession.setDebug(false);
MimeMessage msg = new MimeMessage(mailSession);
try {
msg.setFrom(new InternetAddress(mailFrom));
InternetAddress[] address = {new InternetAddress(mailTo)};
msg.setRecipients(Message.RecipientType.TO,address);
msg.setSubject(mailSubject, "UTF8");
msg.setSentDate(new Date());
msg.setText(mailBody, "UTF8");
Transport.send(msg);
} catch (Exception e) {
}
}
public static void main(String[] args) {
Send();
}
}
When I run this I end up with '=?UTF8?Q?Actualizaci=C3=B3n?=' in the
subject & the contents of 'This message uses a character set that is
not supported by the Internet Service. To view the original message
content, open the attached message. If the text doesn't display
correctly, save the attachment to disk, and then open it using a
viewer that can display the original character set.'.
The email server can deal with these special characters as I can use
Outlook to create the email I require.
Thanks in advance for any solutions.
Andee