这个问题还差不多。
我觉得只要你能够发送文本格式的文件,只要将哪些内容用HTML语言做一下规划一同发出去,应该是可以的。不过,我没有测试过,个人观点,希望大家批判。
我觉得只要你能够发送文本格式的文件,只要将哪些内容用HTML语言做一下规划一同发出去,应该是可以的。不过,我没有测试过,个人观点,希望大家批判。
解决方案 »
- 菜鸟求解,谢了
- 一个关于类继承和隐藏的问题,不要运行程序,您知道运行结果吗?为什么?头想疼了。
- 大家帮忙呀!!!我错在那里?????不防行一下试试呀!!!!!!!!!
- 如何入门~回答的都给分~谢谢大家~多多发表
- 请问,怎么在插入数据后能获取该条记录的主键id?
- 怎样可以使JAVA入门快点???
- 简单的字符串问题,欢迎参与!
- 连接占线导致另一个 hstmt,一般是什么原因引起的???20分!
- 一个很简单的入门者的问题!
- java.util.ArrayList.clone是不是彻底的克隆?
- 又是一个java的菜问题,大家来抢分呀。:)
- writeObject()写字符串成功,但向量就不行,为什么?
String msgText=getHtmlMessageText(...);
msg.setContent(msgText,"text/html");
/**
发送Email 的JavaBean@author sharetop
@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);
}
}
给分吧,我的分太少了!!!!!!
没问题了我一直用的一个Bean了。不过不能发附件而已。快给分吧,我饿死了。
再给一个例子吧:
import java.io.*;
import java.util.*;
import java.net.*;public class test
{
public static void main(String[] args)
{
try{
Email em = new Email("smtp.21cn.com","[email protected]","[email protected]");
em.mail("测试邮件","<font color=blue>我在北京</font>");
System.out.println("ok");
}
catch(Exception e){
e.printStackTrace(System.err);
}
}
}
to xiaoyou(三尺剑):不好意思,我是去分多,进分少,唉!日子难过呀。你有分转让,我当然是来者不拒了^_^