Store store = Session.getDefaultInstance().getStore();
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];
// Create message.
Message msg = new Message(sentfolder);
// Add TO Recipients.
Address toList[] = new Address[1];
try {
toList[0]= new Address("[email protected]", "Some Email");
} catch(AddressException e) {
System.out.println(e.toString());
}
try {
msg.addRecipients(Message.RecipientType.TO, toList);
} catch (MessagingException e) {
System.out.println(e.toString());
}
// Add CC Recipients.
Address ccList[] = new Address[1];
try {
ccList[0]= new Address("[email protected]", "some address");
} catch(AddressException e) {
System.out.println(e.toString());
}
try {
msg.addRecipients(Message.RecipientType.CC, ccList);
} catch (MessagingException e) {
System.out.println(e.toString());
}
// Add the subject.
msg.setSubject("A Test Email");
// Add the message body.
try {
msg.setContent("This is a test message.");
} catch(MessagingException e) {
// Handle messaging exceptions.
}
// Send the message.
try {
Transport.send(msg);
} catch(MessagingException e) {
System.out.println(e.getMessage());
}
System.out.println("Email sent successfully.");
-1
A
回答
1
1
您是否正在模擬器上運行此?如果是這樣,哪個開發環境(日食或JDE)?你是否開始使用MDS或者你在使用ESS? (MDS的4,你不需要ESS)。
就個人而言,我用eclipse插件使用,然後設置運行時配置推出MDS。
然而,在這之前,你需要編輯rimpublic.property文件來配置它連接到你的電子郵件服務器(如果您使用的是遠程電子郵件服務器)。如果您要使用本地郵件客戶端,請配置MDS以將其用作傳遞。
讓我知道你的設置/配置是什麼,我會盡力幫助更多。
你得到任何錯誤或異常? – 2010-10-09 22:37:48