Ik heb hier een voorbeeldprogrammatje gevonden om een email te verzenden met javamail. Ik weet totaal niet hoe dat ik die argumenten van de methode send moet inbrengen.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
/**
* A simple email sender class.
*/
public class SimpleSender
{
/**
*Main method to send a message given on the command line.
*/
public static void main(String args[])
{
try
{
String smtpServer=args[0];
String to=args[1];
String from=args[2];
String subject=args[3];
String body=args[4];
send(smtpServer,to,from,subject,body);
}
catch (Exception ex)
{
System.out.println("Usage:java com.lotontech.mail.SimpleSender"
+" smtpServer toAdress fromAddress FromAddress subjectText bodyText");
}
System.exit(0);
}
/**
*"send" method to send the message.
*/
public static void send(String smtpServer,String to,String from
,String subject,String body)
{
try
{
Properties props=System.getProperties();
//Attaching to default Session, or we could start a new one
props.put("mail.smtp.host",smtpServer);
Session session=Session.getDefaultInstance(props,null);
//Create a new message
Message msg=new MimeMessage(session);
//Set the FROM and TO fields
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to,false));
//We could include CC recipients too
//if (cc !=null)
//msg.setRecipients(Message.RecipientType.cc
//,InternetAdress.parse(cc,false));
//Set the subject and the body text
msg.setSubject(subject);
msg.setText(body);
//Set some other header information
msg.setHeader("X-Mailer","Lotontechmail");
msg.setSentDate(new Date());
//Send the message
Transport.send(msg);
System.out.println("Message sent OK.");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
Als iemand het zou weten, weet iets te zeggen.
Dankt u.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
/**
* A simple email sender class.
*/
public class SimpleSender
{
/**
*Main method to send a message given on the command line.
*/
public static void main(String args[])
{
try
{
String smtpServer=args[0];
String to=args[1];
String from=args[2];
String subject=args[3];
String body=args[4];
send(smtpServer,to,from,subject,body);
}
catch (Exception ex)
{
System.out.println("Usage:java com.lotontech.mail.SimpleSender"
+" smtpServer toAdress fromAddress FromAddress subjectText bodyText");
}
System.exit(0);
}
/**
*"send" method to send the message.
*/
public static void send(String smtpServer,String to,String from
,String subject,String body)
{
try
{
Properties props=System.getProperties();
//Attaching to default Session, or we could start a new one
props.put("mail.smtp.host",smtpServer);
Session session=Session.getDefaultInstance(props,null);
//Create a new message
Message msg=new MimeMessage(session);
//Set the FROM and TO fields
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to,false));
//We could include CC recipients too
//if (cc !=null)
//msg.setRecipients(Message.RecipientType.cc
//,InternetAdress.parse(cc,false));
//Set the subject and the body text
msg.setSubject(subject);
msg.setText(body);
//Set some other header information
msg.setHeader("X-Mailer","Lotontechmail");
msg.setSentDate(new Date());
//Send the message
Transport.send(msg);
System.out.println("Message sent OK.");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
Als iemand het zou weten, weet iets te zeggen.
Dankt u.