我想以编程方式发送电子邮件。为此,我写了下面的代码:
if(field == m_btnSend)
{
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("arindam.hit@gmail.com", "Arindam");
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();
}
}
我在MDS模拟器中运行它。现在我想通过邮件收件箱看到这封邮件,如果我通过模拟器浏览器打开我的邮件。怎么可能?
感谢。
答案 0 :(得分:0)
检查我网站上的以下代码。 sending-email-with-attachment-in Blackberry
答案 1 :(得分:0)
首先阅读this在黑莓jde模拟器中运行代码后,从开始 - >所有程序 - >运动中的研究 - >选择MDS然后阅读此documentation。执行步骤直到6和您将在Messages文件夹中看到通过编程应用程序发送的邮件 您无需输入密码和用户名
答案 2 :(得分:0)
试试这段代码 - 对于发送电子邮件,BIS在您的设备中处于活动状态。它在Simulator中不起作用。此外,您的设备中还配置了一封电子邮件。
try
{
recipients[0]= new Address(id_,name_);
//add the recipient list to the message
msg.addRecipients(Message.RecipientType.TO, recipients);
//set a subject for the message
msg.setSubject("Test email");
//sets the body of the message
msg.setContent("123456789---------------");
//sets priority
msg.setPriority(Message.Priority.HIGH);
//send the message
Transport.send(msg);
}
catch (Exception me)
{
Dialog.alert(me+"");
System.err.print(me);
}
答案 3 :(得分:0)
这是使用邮件发送附件的代码,它在设备上运行良好:
private void sendmail()
{
try
{
Address[] address = new Address[1];
address[0] = new Address(" "," ");
Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);
msg=new Message(folders[0]);
msg.addRecipients(Message.RecipientType.TO, address);
msg.setSubject(" ");
SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart,"application/pdf",pdfName,data);
multipart.addBodyPart(attach);
msg.setContent(multipart);
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,new MessageArguments(msg));
try
{
Transport.send(msg);
}
catch(SendFailedException e)
{
System.out.println("messages for sent : : : : : : "+e.getMessage());
}
}