再说,发送失败会抛出SendFailedException,通过SendFailedException的三个方法可以查询具体信息 Address[] getInvalidAddresses() Return the addresses to which this message could not be sent. Address[] getValidSentAddresses() Return the addresses to which this message was sent succesfully. Address[] getValidUnsentAddresses() Return the addresses that are valid but to which this message was not sent.
Return the addresses to which this message could not be sent.
Address[] getValidSentAddresses()
Return the addresses to which this message was sent succesfully.
Address[] getValidUnsentAddresses()
Return the addresses that are valid but to which this message was not sent.
VRFY
EXPN以上两个命令就是检查接收方邮箱是否合法的方法,是不是说外部的邮件出于安全的考滤会屏敝此判断??
Socket socket=new Socket("smtp.xxx.com",25);
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
out.write("RCPT TO:[email protected]");
out.flush();
BufferedReader in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line=in.readLine();
int result=Integer.parseInt(line);
if(result!=250)
System.out.println("收件人地址有错误");
并且我要及时知道邮件的投递情况:
如果收件人正常收到了发送的邮件,我需要给发件人一个状态信息,告诉他,邮件已经成功发送给对方了。如果接收人的邮件地址是错误的,那我要及时给发件人一个状态消息,告诉他,由于邮件的地址错误,所以无法邮件投递失败。但用javamail来发送邮件时,无法及时的知道james邮件服务器与外部邮箱的一个交互过程,导致没有办法及时的监控邮件的状态。James邮件服务是我们自己配置的,如果收件人是内部的邮件地址,很好处理,但如果是外部的地址就没办法处理了,不知道这种情况是不是可以用socket来处理
http://blog.csdn.net/CrazyGou/archive/2007/06/13/1649834.aspx
? 我明白了,用javamail貌似是没办法直接交互的,用socket来做是可以的
Socket socket=new Socket("smtp.xxx.com",25);
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
out.write("RCPT TO:[email protected]");
out.flush();
BufferedReader in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line=in.readLine();
int result=Integer.parseInt(line);
if(result!=250)
System.out.println("收件人地址有错误");
---------------------------------------------------------
这样做是不行的
必须获取主机的MX(Mail Exchange)记录,然后与其邮件交换服务器交互,而不是smtp.xxx.com。
再就是命令必须按照次序写入,先HELO再MAIL FROM再RCPT TO,否则服务器可能拒绝。还有,RCPT TO后返回的一般不会仅是一个数字,可能如250-ok,不能parseInt按照我提供的方法(http://blog.csdn.net/CrazyGou/archive/2007/06/13/1649834.aspx)验证是有效率&资源问题,但也只能这么做。是否必要不是绝对的,需要自己权衡
如果只是偶尔有发送邮件的需求,可以不用James做邮件服务器,用JavaMail直接发信(http://blog.csdn.net/CrazyGou/archive/2007/06/13/1649828.aspx),send方法返回false表示发送失败。可根据JavaMail异常判断发送失败原因
----------------------------------------------------------
请问可否说详细点??