JAVA Mail ���ʼ�������
|
javamail.jsp ��������
<%@page contentType="text/html;charset=gb2312"%>
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<html>
<head>
<title>JavaMail �����ʼ�����ϵͳ</title>
</head>
<body>
<%
// ���±���Ϊ�û������Լ����������
String smtphost = "smtp.now.net.cn"; // �����ʼ�������
String user = "yauboo"; // �ʼ���������¼�û���
String password = "xxx"; // �ʼ���������¼����
String from = "yauboo@now.net.cn"; // �������ʼ���ַ
String to = "yauboo@now.net.cn"; // �������ʼ���ַ
String subject = "Java Mail Subject!"; // �ʼ�����
String body = "Java Mail Body!"; // �ʼ�����
// ����Ϊ���ͳ����û�����Ķ�
try {
Properties props = new Properties();
props.put("mail.smtp.host", smtphost);
props.put("mail.smtp.auth","true");
Session ssn = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(ssn);
InternetAddress fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
InternetAddress toAddress = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject(subject);
message.setText(body);
Transport transport = ssn.getTransport("smtp");
transport.connect(smtphost, user, password);
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
//transport.send(message);
transport.close();
%><p>����ʼ��ѷ��ͣ��뷵�ء�</p><%
} catch(Exception m) {
out.println(m.toString());
}%>
</BODY>
</HTML>
|
|