![]() |
|
Si può spedire o ricevere email da un'Applet Java?
E' possibile. Ti allego un esempio che ho avuto da un tecnico Sun Utilizzare previa installazione di JavaMail
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
/**
* usage: sendmessage to from smtphost multipart
*
* Send a simple text/plain message to the "to"
* address, from the "from" address, using the
* smtphost as the machine with the smtp server
* running.
*
* if multipart is "true" send a multipart message
* else if multipart is "false" send a text/plain
* message.
*/
public class sendmessage
{
public static void main(String[] args)
{
if (args.length != 4)
{
System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false>");
System.exit(1);
}
boolean debug = false;
// change to get more information
String msgText = "A body.
the second line.";
String msgText2 = "Another body.
more lines";
boolean sendmultipart = Boolean.valueOf(args[3]).booleanValue();
// set the host
Properties props = new Properties();
props.put("mail.smtp.host", args[2]);
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
try // create a message
{
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(args[1]);
msg.setFrom(from);
InternetAddress[] address = {new InternetAddress(args[0])};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("JavaMail APIs Test");
if (!sendmultipart) // send a plain text message
{
msg.setContent(msgText, "text/plain");
}
else
{
// send a multipart message
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
}
Transport.send(msg);
}
catch (MessagingException mex)
{
mex.printStackTrace();
}
}
}
by sergiolc[AT]iol.itPS: RTFM. Un'Applet *non puo'* aprire una socket verso un host diverso da quello da dove e' stata prelevata, a meno di non richiederne esplicitamente i diritti, accompagnando la richiesta con una firma digitale (e solo in Java 1.1, con un browser che supporti le signed Applets - leggi Communicator). Indi, o piazzi la tua Applet su [lo stesso server su cui gira il server di mail -cs] - oppure *non va*. |
IN EVIDENZA
Una slidegallery con jQuery
Pagamenti online con PayPal e PHP
Breve guida a jQuery
Effetto ombra su testo con Photoshop
Guadagna col tuo sito grazie a TradeD...
Guida XHTML
Riscrivere le URL con Asp
Riavviare IIS
HTTP 500 internal server error
Generare password casuali in Javascri...
Errore 80004005: Cannot update. Datab...
Introduzione ad Ajax ed Asp con Jscri...
Referenze dei Tag Html
Stringhe di connessione via ODBC e Ol...
Referenze dei fogli di stile Css
Le espressioni regolari in Javascript
|
||||
© 2001/2010 lukeonweb.net - A cura di Luca Ruggiero, Partita IVA 05564851219 -
Privacy |
Pubblicità |
Contatti
| |||||