红联Linux门户
Linux帮助

Java核心代码例程之:SmtpMail.java

发布时间:2006-06-15 10:27:04来源:红联作者:[Hl.y]
[align=center]
引用:
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);


}


}
[/align]
文章评论

共有 0 条评论