浏览 4873 次
锁定老帖子 主题:谁有java做的发送email的例子吗?
该帖已经被评为隐藏帖
|
|
---|---|
作者 | 正文 |
发表时间:2006-12-11
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2006-12-11
package com;
import java.util.*; import javax.mail.*; import javax.mail.internet.*; import java.util.Date; import javax.activation.*; import java.io.*; import java.net.*; public class sendMail { static PrintStream ps = null; static DataInputStream dis = null; public static void send(String str) throws IOException { ps.println(str); ps.flush(); System.out.println("java sent:"+str); } public static void receive() throws IOException { String readstr = dis.readLine(); System.out.println("SMTP response:"+readstr); } public static void main(String args[]) { String HELO="HELO"; String MAIL_FROM="jwfdp@yahoo.com"; String RCPT_TO="jwfdp@hotmail.com"; String SUBJECT="SUBJECT:java is cool!"; String DATA = "DATA"; String BODY = "Java send this!\r\n.\r\n"; Socket smtp =null; try { smtp=new Socket("smtp.yahoo.com",25); OutputStream os = smtp.getOutputStream(); ps = new PrintStream(os); InputStream is = smtp.getInputStream(); dis = new DataInputStream(is); } catch(Exception e) { e.printStackTrace(); } try { String loc = InetAddress.getLocalHost().getHostName(); send(HELO+loc); receive(); send(MAIL_FROM); receive(); send(RCPT_TO); receive(); send(DATA); receive(); send(SUBJECT); receive(); send(BODY); receive(); smtp.close(); System.out.println("==end========"); } catch(Exception e) { e.printStackTrace(); } } } 就是这段代码,为什么smtp=new Socket("smtp.yahoo.com",25);有错呢 |
|
返回顶楼 | |
发表时间:2006-12-11
用jakarta commons-emails 很简单: java 代码
|
|
返回顶楼 | |
发表时间:2006-12-11
谢谢了哈,怎么我还是发不出去啊
public static void test() throws EmailException { SimpleEmail email = new SimpleEmail(); email.setHostName("mail.yahoo.com"); email.setAuthentication("username","password"); email.addTo("wei@movaya.com"); email.setFrom("jwfdp@yahoo.com.cn"); email.setSubject("主题"); email.setMsg("内容"); email.send(); } 错误报告: Exception in thread "main" org.apache.commons.mail.EmailException: Sending the email to the following server failed : mail.yahoo.com:25 at org.apache.commons.mail.Email.sendMimeMessage(Email.java:873) at org.apache.commons.mail.Email.send(Email.java:898) at com.testDate.test(testDate.java:132) at com.testDate.main(testDate.java:52) Caused by: javax.mail.AuthenticationFailedException at javax.mail.Service.connect(Service.java:264) at javax.mail.Service.connect(Service.java:134) at javax.mail.Service.connect(Service.java:86) at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:138) at javax.mail.Transport.send0(Transport.java:150) at javax.mail.Transport.send(Transport.java:80) at org.apache.commons.mail.Email.sendMimeMessage(Email.java:863) ... 3 more |
|
返回顶楼 | |
发表时间:2006-12-21
没人回答啊
|
|
返回顶楼 | |