Invio di un messaggio con un allegato
- Importare le classi e le interfacce richieste.
import net.rim.blackberry.api.mail.Message;
import net.rim.blackberry.api.mail.MessagingException;
import net.rim.blackberry.api.mail.Multipart;
import net.rim.blackberry.api.mail.Session;
import net.rim.blackberry.api.mail.SupportedAttachmentPart;
import net.rim.blackberry.api.mail.Transport;
- Creare un nuovo oggetto Multipart per creare un messaggio Multipart.
byte[] data = new byte[256];
MultiPart multipart = new MultiPart();
- Creare un oggetto SupportedAttachmentPart, designando l'oggetto Multipart come padre, per creare ogni componente della schermata.
SupportedAttachmentPart attach = new SupportedAttachmentPart( multipart,
"application/x-example", "filename", data);
- Richiamare MultiPart.addBodyPart(SupportedAttachmentPart) per aggiungere ogni oggetto supportedAttachmentPart all'oggetto Multipart.
multipart.addBodyPart(attach);
- Richiamare Message.setContent(Multipart) e fornire come parametro l'oggetto Multipart per impostare il contenuto dell'allegato.
msg.setContent(multipart);
- Richiamare Session.getTransport() e memorizzare l'oggetto restituito in una variabile di tipo Transport. L'oggetto Transport rappresenta il protocollo di trasporto per la messaggistica.
Transport trans = Session.getTransport();
- Richiamare Transport.send(Message).
try
{
trans.send(msg);
}
catch(MessagingException e)
{
System.out.println(e.getMessage());
}
Le informazioni sono state utili? Inviateci i vostri commenti.