需要一个能发送html邮件的javabeans

hello_hf1 2001-07-20 03:35:18
谁能提供吗?
...全文
210 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hello_hf1 2001-07-24
  • 打赏
  • 举报
回复
对不起,第一封信没改过来就发出去了
sharetop 2001-07-24
  • 打赏
  • 举报
回复

没问题就给分吧。
sharetop 2001-07-23
  • 打赏
  • 举报
回复

给你一个吧,不用javamail,那个要带着一个包走。源码如下:

/**
发送Email 的JavaBean

@author yancheng(sitechasia.com)
@version 1.0.1
created date:2001-4-25

采用直接写Socket方式发送email
关于SMTP(SIMPLE MAIL TRANSFER PROTOCOL)命令,
参考 http://www.faqs.org/rfcs/rfc821.html

*/

import java.io.*;
import java.util.*;
import java.net.*;

public class Email
{
private static final String CONTENT_TYPE = "text/html";

private String smtpServer=null;
private String fromMail=null;
private String toMail=null;

public Email(String smtp,String from,String to)
{
this.smtpServer=smtp;
this.fromMail=from;
this.toMail=to;
}

public void mail(String subject,String content) throws MailException
{

try{

//打开邮件服务器port:25
Socket s = new Socket(smtpServer,25);

//用于socket读写数据
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));

String res = null; //smtp服务器返回信息

out.println("HELO "+smtpServer);
res=in.readLine();
if( !res.startsWith("220") ) throw new MailException("MailException:"+res);

out.println("MAIL FROM: "+fromMail);
res = in.readLine();
if( !res.startsWith("250") ) throw new MailException("MailException:"+res);

out.println("RCPT TO: "+toMail);
res = in.readLine();
if( !res.startsWith("250") ) throw new MailException("MailException:"+res);

out.println("DATA");
res = in.readLine();
if( !res.startsWith("250") ) throw new MailException("MailException:"+res);

out.println("Subject:"+subject);
out.println("From:"+fromMail);
out.println("To:"+toMail);
out.println("Content-Type: text/html; charset=gb2312");
out.println(content);

out.println(".");
res = in.readLine();
if( !res.startsWith("354") ) throw new MailException("MailException:"+res);

out.println("QUIT");
s.close();
}
catch(UnknownHostException x) {
throw new MailException("MailException:"+x.getMessage());
}
catch(IOException x){
throw new MailException("MailException:"+x.getMessage());
}
}//end method mail

}//end class Email

//发送邮件违例类
class MailException extends Exception
{
public MailException(String msg)
{
super(msg);
}
}

调用方法如下:


import java.io.*;
import java.util.*;
import java.net.*;

public class test
{

public static void main(String[] args)
{
try{
Email em = new Email("mail.sitechasia.com","ycshowtop@21cn.com","cyan@sitechasia.com");
em.mail("测试邮件","<font color=blue>北京市西三环路甲19号企业网大厦</font>");
System.out.println("ok");
}
catch(Exception e){
e.printStackTrace(System.err);
}
}

}
hello_hf1 2001-07-23
  • 打赏
  • 举报
回复
多谢了
hello_hf@21cn.com
hello_hf1 2001-07-23
  • 打赏
  • 举报
回复
多谢了
hello_hf@21cn.com
nil2000 2001-07-23
  • 打赏
  • 举报
回复
前幾天我剛寫了一個,用javamail1.2寫的,你想要的話,給出email,我發給你,源代碼可以一起給.
Dureek 2001-07-23
  • 打赏
  • 举报
回复
急着要? faint ...
要你想做的话 ... 20号当天就已经差不多了 ...
hello_hf1 2001-07-23
  • 打赏
  • 举报
回复
没有时间了。领导急着要,谁有就帮帮忙吧
Dureek 2001-07-23
  • 打赏
  • 举报
回复
自己做一个好不好呢? javamail里好象有例子 ...
hello_hf1 2001-07-23
  • 打赏
  • 举报
回复
谁能提供吗?
sharetop 2001-07-23
  • 打赏
  • 举报
回复

嘿,如果你测试的话换个信箱!!


Email em = new Email("mail.sitechasia.com", //这是smtp服务器
"ycshowtop@21cn.com", //这是发信人
"cyan@sitechasia.com"); //这是收信人


em.mail("测试邮件", //标题
"<font color=blue>北京市西三环路甲19号企业网大厦</font>" //内容
);

别给我发信了,多谢!



dragonerfish 2001-07-20
  • 打赏
  • 举报
回复
关注!!!
hello_hf1 2001-07-20
  • 打赏
  • 举报
回复
谁能提供吗?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧