Java核心代码例程之:JavaMail----SmtpMail.java
2008-01-05 08:39:49 来源:WEB开发网核心提示:import java.io.*;import java.util.*;import javax.mail.*;import javax.mail.internet.*;import javax.activation.*;public class SmtpMail{ public static void main(St
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SmtpMail
{
public static void main(String args[]) throws Exception
{
// create some PRoperties and get the default session
Properties props = new Properties();
props.put("mail.smtp.host", "yoursmtpserver");
Session session = Session.getDefaultInstance(props, null);
Message message = new MimeMessage(session);
// create a message
InternetAddress ia[] = new InternetAddress[1];
ia[0] = new InternetAddress("myself@abc.com", "Me");
message.setFrom(new InternetAddress("test@abc.com", "some developer"));
message.setRecipients(Message.RecipientType.TO, ia);
message.setSubject("Hello World");
message.setText("Hello World! This message was generated using JavaMail.");
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect();
transport.send(message);
}
}
更多精彩
赞助商链接