¡¾·±ÌåÖÐÎÄ¡¿
¡¾ÉèΪÊ×Ò³¡¿
¡¾¼ÓÈëÊղء¿
µ±Ç°Î»ÖãºJSP¼¼ÊõÊ×Ò³ >> ÓʼþÏà¹Ø >> ·¢ÓʼþʱÖÕÓÚ¿ÉÒÔͨ¹ýsinaµÄsmtpÑéÖ¤ÁË£¨¸½´úÂ룩

·¢ÓʼþʱÖÕÓÚ¿ÉÒÔͨ¹ýsinaµÄsmtpÑéÖ¤ÁË£¨¸½´úÂ룩

2004-10-01 08:26:10  ×÷Õߣº  À´Ô´£º»¥ÁªÍø  ä¯ÀÀ´ÎÊý£º93  ÎÄ×Ö´óС£º¡¾´ó¡¿¡¾ÖС¿¡¾Ð¡¡¿
¼ò½é£ºimport javax.mail.*; import javax.mail.internet.*; import java.util.*; public class sendMail {     public static void main(String args[]) throws Exception    &...

import javax.mail.*;

import javax.mail.internet.*;

import java.util.*;

public class sendMail

{

public static void main(String args[]) throws Exception

{

String host = "smtp.sina.com.cn";

String from = "javamail@sina.com";

String to = "javamail@china.com";

String username = "javamail";

String password = "password";

// Get system properties

// Properties props = System.getProperties(); ºÜ¶àÀý×ÓÖÐÊÇÕâÑùµÄ£¬ÆäʵÏÂÃæÕâ¾ä¸üºÃ£¬¿ÉÒÔÓÃÔÚappletÖÐ

Properties props = new Properties();

// Setup mail server

props.put("mail.smtp.host", host);

props.put("mail.smtp.auth", "true"); //ÕâÑù²ÅÄÜͨ¹ýÑéÖ¤

// Get session

Session session = Session.getDefaultInstance(props);

// watch the mail commands go by to the mail server

session.setDebug(true);

// Define message

MimeMessage message = new MimeMessage(session);

message.setFrom(new InternetAddress(from));

message.addRecipient(Message.RecipientType.TO,

new InternetAddress(to));

message.setSubject("Hello JavaMail");

message.setText("Welcome to JavaMail");

// Send message

message.saveChanges();

Transport transport = session.getTransport("smtp");

transport.connect(host, username, password);

transport.sendMessage(message, message.getAllRecipients());

transport.close();

}

}

ÔðÈα༭£ºadmin
±¾ÎÄÒýÓõØÖ·£º http://www.3pcode.com/jsp/2004/10/9937.htm
Ïà¹ØÎÄÕÂ