您好我想使用java和javax从我的黑莓应用程序发送smtp电子邮件,我已经使用javax邮件从我的Android应用程序发送smtp电子邮件,如下代码:
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
message.setSender(new InternetAddress(sender));
message.setSubject(subject);
message.setDataHandler(handler);
if (recipients.indexOf(',') > 0)
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
else
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
Transport.send(message);
黑莓应用程序中是否有类似的代码可以发送smtp电子邮件?
答案 0 :(得分:1)
试试这个 -
Store store = Session.getDefaultInstance().getStore();
Folder[] folder = store.list(Folder.SENT);
Folder sent = folder[0];
Message msg = new Message(sent);
Address receipent[] = new Address[1];
try
{
receipent[0] = new Address(To_Address, name);
msg.addRecipients(Message.RecipientType.TO, receipent);
msg.setSubject("Test Mail");
msg.setContent("This mail is to remind you that programmatically we can send the mail");
msg.setPriority(Priority.HIGH);
Transport.send(msg);
}
catch (Exception e)
{
e.printStackTrace();
}