Article View: cn.bbs.comp.lang.java
Article #23229SmtpMail(j2ee Authorization)
From: �������
Date: Thu, 07 Aug 2003 01:05
Date: Thu, 07 Aug 2003 01:05
85 lines
4366 bytes
4366 bytes
������: hushui (hushui), ����: linux
�� ��: SmtpMail(j2ee Authorization)
����վ: �����ˮվ (2003��08��06��16:11:54 ������), վ���ż�
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SmtpMail {
public static void main(String[] args) {
String to = "lake.hu@fa-software.com";//�ռ��˵�ַ
String from = "lake.hu@fa-software.com"; //�����˵�ַ
//String host = "211.152.41.106"; //smtp������
// String host = "127.0.0.1"; //smtp������
String host = "172.28.101.50"; //smtp server
int port=25; //�˿ں�,ȱʡΪ25
String m_user="fa_michael"; //������Ҫ��֤���û���
String m_pass="user"; //����
//��html������
String content="urgent mail test ";
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.setProperty("mail.transport.protocol","smtp"); //smtp��
props.setProperty("mail.smtp.host",host); //��������ַ
props.setProperty("mail.smtp.port",""+port); //�˿ں�
//��֤��Ϣ
if(m_user!=null && m_pass!=null && m_user.length()>0 &&
m_pass.length()>0){
props.setProperty("mail.smtp.auth","true");
}
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);//for debug,this line can be removed
try {
// create a message
Message msg = new MimeMessage(session);
msg.setFlag(Flags.Flag.FLAGGED, true); // set the FLAGGED flag
for urgent mail
msg.setHeader("X-Priority","2"); //
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("urgent mail test ");
msg.setSentDate(new Date());
msg.setContent(content,"text/html");
//�����Ҫ��֤�û�(��:smtp.sina.com.cn)����ʹ��connect��sendM
essage
//ע������趨mail.smtp.auth����Ϊtrue
if(m_user!=null && m_pass!=null && m_user.length()>0 &&
m_pass.length()>0){
Transport trans=session.getTransport();
trans.connect(host,m_user,m_pass);
trans.sendMessage(msg,InternetAddress.parse(to));
trans.close();
}
//������Ҫ�û���Ϳ���ʹ�þ�̬���������ɼ�
else Transport.send(msg);
} catch (MessagingException e) {
e.printStackTrace();
Exception ex = null;
if ((ex = e.getNextException()) != null) {
ex.printStackTrace();
}
}
}
}
--
�� ��Դ:�������ˮվ
--
[m[1;34m�� ��Դ:����ˮ˼Դ bbs.sjtu.edu.cn��[FROM: 61.170.239.107][m
Technical Details
Message-ID:
<47Ya94$9aR@bbs.sjtu.edu.cn>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!in.100proofnews.com!in.100proofnews.com!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!news.neu.edu.cn!SJTUShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,GB X-Google-Thread: f6cb0,510a561e7f4fafbe,start X-Google-Attributes: gidf6cb0,public X-Google-ArrivalTime: 2003-08-06 18:08:38 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!in.100proofnews.com!in.100proofnews.com!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!news.neu.edu.cn!SJTU From: hushui.bbs@bbs.sjtu.edu.cn (�������) Newsgroups: cn.bbs.comp.lang.java Subject: SmtpMail(j2ee Authorization) Date: 07 Aug 2003 01:05:01 GMT Organization: ��ˮ˼Դ Message-ID: <47Ya94$9aR@bbs.sjtu.edu.cn> Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit X-Filename: Java/M.1060218292.A Lines: 85