佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1239|回复: 7

谁能教我怎样用java send email????

[复制链接]
发表于 29-1-2008 06:48 PM | 显示全部楼层 |阅读模式
谁能教我怎样用java send email????我想不到要怎么做填什么。。。
这个是老师给我的问题:
import java.io.*;
import java.net.*;


public class EmailSender
{

public static void main(String[] args) throws Exception


{


// Establish a TCP connection with the mail server.






// Create a BufferedReader to read a line at a time.


InputStream is = socket.getInputStream();


InputStreamReader isr = new InputStreamReader(is);


BufferedReader br = new BufferedReader(isr);




// Read greeting from the server.


String response = br.readLine();


System.out.println(response);


if (!response.startsWith("220") {



throw new Exception("220 reply not received from server.";


}




// Get a reference to the socket's output stream.


OutputStream os = socket.getOutputStream();




// Send HELO command and get server response.


String command = "HELO alice\r\n";


System.out.print(command);


os.write(command.getBytes("US-ASCII");


response = br.readLine();


System.out.println(response);


if (!response.startsWith("250") {


throw new Exception("250 reply not received from server.";


}




// Send MAIL FROM command.






// Send RCPT TO command.






// Send DATA command.






// Send message data.




// End with line with a single period.






// Send QUIT command.




}

}

请大家帮帮忙!!!
回复

使用道具 举报


ADVERTISEMENT

发表于 29-1-2008 10:21 PM | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2-2-2008 02:10 PM | 显示全部楼层
我有试看run了可是一直有error
InputStream is = socket.getInputStream();


OutputStream os = socket.getOutputStream();

这两句一直有error哦。。。谁能帮帮我??
回复

使用道具 举报

发表于 2-2-2008 02:45 PM | 显示全部楼层
什么ERR呀?
你以为别人可以猜到你得到什么ERR吗?
回复

使用道具 举报

 楼主| 发表于 2-2-2008 10:04 PM | 显示全部楼层
原帖由 jasonmun 于 2-2-2008 02:45 PM 发表
什么ERR呀?
你以为别人可以猜到你得到什么ERR吗?



不好意思没有写出来....
这就是run过后的error:

EmailSender.java:13: cannot find symbol
symbol  : variable socket
location: class EmailSender
      InputStream is = socket.getInputStream();
                       ^
EmailSender.java:25: cannot find symbol
symbol  : variable socket
location: class EmailSender
      OutputStream os = socket.getOutputStream();
                        ^
2 errors
回复

使用道具 举报

发表于 3-2-2008 02:24 AM | 显示全部楼层
http://www.java2s.com/Code/JavaA ... ringaddrintport.htm

InetAddress addr = InetAddress.getByName("mail server url");
Socket socket = new Socket(addr,21); [应该有这行吧?]
..
InputStream is = socket.getInputStream();
....

[ 本帖最后由 jasonmun 于 3-2-2008 01:13 PM 编辑 ]
回复

使用道具 举报

Follow Us
发表于 3-2-2008 02:48 PM | 显示全部楼层
要declare socket先
回复

使用道具 举报

 楼主| 发表于 11-2-2008 06:37 PM | 显示全部楼层
原帖由 jasonmun 于 3-2-2008 02:24 AM 发表
http://www.java2s.com/Code/JavaA ... ringaddrintport.htm

InetAddress addr = InetAddress.getByName("mail server url";
Socket socket = new Socket(addr,21); [应该有这行吧?]
..
InputStream is = soc ...


谢谢你的帮忙才让我顺利完成....真得很谢谢你哦
回复

使用道具 举报


ADVERTISEMENT

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT


本周最热论坛帖子本周最热论坛帖子

ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 24-9-2025 06:47 PM , Processed in 0.101469 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表