发送的时候没有报错,可是收件箱收不到发送的邮件。
代码:
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class JavaMail {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
Properties props = new Properties();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol", "smtp");
Session session = Session.getInstance(props);
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setText("收到没?");
msg.setFrom(new InternetAddress("[email protected]"));
Transport transport = session.getTransport();
transport.connect("smtp.isoftstone.com", 25, "[email protected]", "密码");
transport.sendMessage(msg,
new Address[]{new InternetAddress("[email protected]")});
transport.close();
}
}控制台信息:
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.isoftstone.com", port 25, isSSL false
220 IsoftStone ESMTP Service Ready
DEBUG SMTP: connected to host "smtp.isoftstone.com", port: 25EHLO iss130001000412
250-StormMail ESMTP service ready
250-AUTH LOGIN
250-SIZE 15728640
250 Ok
DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "SIZE", arg "15728640"
DEBUG SMTP: Found extension "Ok", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 
AUTH LOGIN
334 VXNlcm5hbWU6
eWd6dW9AaXNvZnRzdG9uZS5jb20=
334 UGFzc3dvcmQ6
enlnMTIzKioqKg==
235 Go ahead.
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 ok
RCPT TO:<[email protected]>
250 ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   [email protected]
DATA
354 Please start mail input.
From: [email protected]
Message-ID: <19727353.0.1254127986442.JavaMail.ygzuo@iss130001000412>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base645L2g5aW95ZCX77yf
.
250 Mail queued for delivery.
QUIT
221 Closing connection. Good bye.收件箱 换了几种都不行,等的时间也够长。应该是程序的问题吧,各位大虾请指教。

解决方案 »

  1.   

    250 Mail queued for delivery.
    这里 250 表示对方服务器已经接受到邮件了,250是接收的服务器返回的信息,但是用户的收件箱却没有这个邮件,迷茫中
      

  2.   

    要这么久.....一天的等待太漫长了吧,这样无法商用吧。那些很快能收到的是怎么搞的?一开始,我用sina sohu的邮箱发,都不能发送。后来改用公司的,可以发了,但等了近1小时也收不到邮件。
      

  3.   

    程序改成这样可以接收到邮件了:package com.mail;import java.util.Properties;import javax.mail.Authenticator;
    import javax.mail.Message;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.Message.RecipientType;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;public class DemoMail {
    public static void main(String[] args) throws Exception{
    Properties prop= new Properties();
    prop.setProperty("mail.smtp.auth", "true");
    prop.setProperty("mail.transport.protocol", "smtp");
    //设置接收邮件的服务器
    prop.setProperty("mail.host", "smtp.isoftstone.com");
    Session session = Session.getInstance(prop,
    new Authenticator() //把发邮件的用户名和密码保存给session
    {
    protected PasswordAuthentication getPasswordAuthentication()
    {
    return new PasswordAuthentication("[email protected]","密码");
    }
    }
    );
    session.setDebug(true); //显示调试信息
    Message msg=new MimeMessage(session);
    //发件人,邮件里显示的
    msg.setFrom(new InternetAddress("[email protected]"));
    msg.setSubject("中文主题");
    //邮件正文
    msg.setContent("<span style='color:red'>中文:呵呵</span>", "text/html;charset=utf-8");
    //设置收件人
    msg.setRecipients(RecipientType.TO, InternetAddress.parse("[email protected],[email protected]"));
    //发送邮件
    Transport.send(msg);
    }
    }只是不知道 我第一种方法错在什么地方