J2ME /黑莓 - 如何使用附件发送电子邮件从应用程序? [英] j2me/BlackBerry - How to send Email with Attachment from Application?
本文介绍了J2ME /黑莓 - 如何使用附件发送电子邮件从应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿我建立在用户可以发送电子邮件给一个人的应用程序。
用户输入向其电子邮件是在编辑领域被发送,然后presses发送按钮的电子邮件必须带有附件交付的人的电子邮件ID。
hey i am building an application in which user can send an email to a person. The user enters the email id of the person to whom email is to be sent in a Edit field and then presses a send button the email must be delivered with an attachment.
我怎么能做到这一点??????
how can i do it??????
读音字google搜索后真的很困惑。
有人可以告诉我确切的方法
i m really confused after googling. can someone tell me the exact way
另外,我不能从模拟器发送电子邮件,如果我的COD文件是无符号
also,cant i send email from simulator if my cod file is unsigned
在此先感谢
推荐答案
试试这个。
Address[] address = new Address[1];
try {
address[0] = new Address(email,name);
} catch (AddressException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
byte[] data = readFile();
Multipart multipart = new Multipart();
SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart,
"application/x-example", "test.txt", data);
multipart.addBodyPart(attach);
Message msg = new Message();
// add the recipient list to the message
try {
msg.addRecipients(Message.RecipientType.TO, address);
// set a subject for the message
msg.setSubject("Mail from mobile");
msg.setContent(multipart);
} catch (MessagingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Transport.send(msg);
} catch (MessagingException e) {
System.out.println(e.getMessage());
}
private static byte[] readFile() {
String fName ="file:///store/home/user/test.txt";
byte[] data = null;
FileConnection fconn = null;
DataInputStream is = null;
try {
fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
is = fconn.openDataInputStream();
data = IOUtilities.streamToBytes(is);
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
try {
if (null != is)
is.close();
if (null != fconn)
fconn.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
return data;
}
这篇关于J2ME /黑莓 - 如何使用附件发送电子邮件从应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文