Socket s = new Socket("centech-ops.com", 25);
out = new PrintWriter(s.getOutputStream());
in = new BufferedReader(new
InputStreamReader(s.getInputStream()));
send(null);
send("HELO " + "OPSSERVER");
send("MAIL FROM: " + fadd);
send("RCPT TO: " + sadd);
send("DATA");
out.println("Subject: "+sname+"您好"+ "\n");
out.flush();
out.println("From: "+fname+" <"+fadd+">"+ "\n");
out.flush();
......假如以Socket方式发送
Subject可以这样发,那么用户名和密码该写在哪里?
out = new PrintWriter(s.getOutputStream());
in = new BufferedReader(new
InputStreamReader(s.getInputStream()));
send(null);
send("HELO " + "OPSSERVER");
send("MAIL FROM: " + fadd);
send("RCPT TO: " + sadd);
send("DATA");
out.println("Subject: "+sname+"您好"+ "\n");
out.flush();
out.println("From: "+fname+" <"+fadd+">"+ "\n");
out.flush();
......假如以Socket方式发送
Subject可以这样发,那么用户名和密码该写在哪里?
解决方案 »
- JAVA问题求解
- 关于JUnit使用的一点心得
- 鼠标移动程序——在线急等
- JTree的问题,请教!
- 急急急急!!!!!!关于用JAVA向远程web服务器提交请求的代码
- 没有错误,但是数据库不更新?????
- 解题||指点||提供资料==绝对有高分!(100%承诺能帮解决重点者200分以上)
- 连接SQLSERVER2000的问题
- 请注意,我来说一点,关于程序员薪金问题
- new double[3 + generator.nextInt(4)];是什么意思?新手求助
- ★★★★★★紧急求救!!!为什么下载JDK1.4一到99%就出现错误!!!★★★★★
- 如何在LINUX的红帽7。0版上安装JAVA的开发工具
import javax.mail.Authenticator;/**
* <p>Title: javamail api</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: halitech</p>
* @author david guo
* @version 1.0
*/ public class MyAuthenticator extends Authenticator {
public MyAuthenticator() {
super();
}
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username","password");
}
}
调用:
// Get system properties
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth","true");
// Setup mail server
Authenticator auth = new MyAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
......................记得给分啊
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth","true");
Session session = Session.getDefaultInstance(props, null);
就可以,但是不是所有的服务器都要求发信验证,163.com就不许要,
sina就需要。不用严整类也可以。我试过了。当然用的话,有什么好处就不止到了。