从错误看好象是你的与名写错了。呵呵
不能这么简单吧。
另外:
你的程序能用sina.com.cn做smtp服务器?
我也做过一个这样的程序。
一般的商用邮件服务器为了防止你利用他的smtp服务器进行垃圾邮件传播
都会要求你进行身份验证的,这个问题你解决了么?
如何实现,谢谢。

解决方案 »

  1.   

    peter207 (辉) :
    把你的代码贴出来吧,或者发到我的电子邮件
    [email protected](巴特鲁) :
    要求认证的smtp,你您可以使用Authenticator抽象类的子类,并通过 getPasswordAuthentication()方法返回一个 PasswordAuthentication 
    实例,在该实例中把用户名和密码传递进去即可
    具体可参见sun的教程:
    http://cn.sun.com/developers/onlineTraining/JavaMail/
      

  2.   

    这个程序也是csdn的一位网友写的,我修改了一下。-------------
    import java.util.*; 
    import javax.mail.*; 
    import javax.mail.internet.*; 
    import javax.activation.*; public class SimpleSendMessage {  public static void main(String[] args) {  String host = "smtp.sina.com.cn"; //或者host="202.106.187.180";都可用
    //String host = "61.166.155.284"; //自己的服务器,不可用
    String to = "[email protected]";
    String from = "[email protected]"; //可随便写
    String subject = "mail test"; 
    String messageText = "I am sending a message using "; 
    boolean sessionDebug = false;  // Create some properties and get the default Session. 
    Properties props = System.getProperties(); 
    props.put("mail.host", host); 
    props.put("mail.transport.protocol", "smtp"); 
    props.put("mail.smtp.auth", "true");  //允许smtp校验

    try { 
    Session session =Session.getInstance(props,new MailAuthenticator("username","passwd"));//sina的帐号和密码
    PasswordAuthentication psw=new PasswordAuthentication("username","passwd");//sina的帐号和密码
    session.setPasswordAuthentication(new URLName(host),psw);

    session.setDebug(sessionDebug); 
     
    Message msg = new MimeMessage(session);  msg.setFrom(new InternetAddress(from)); 
    InternetAddress[] address = {new InternetAddress(to)}; 
    msg.setRecipients(Message.RecipientType.TO, address); 
    msg.setSubject(subject); 
    msg.setSentDate(new Date()); 
    msg.setText(messageText); 

    ////增加附件
    Multipart mailBody = new MimeMultipart();
    MimeBodyPart mainBody=new MimeBodyPart();
    mainBody.setText("hello !");
    mailBody.addBodyPart(mainBody);

    FileDataSource fds=new FileDataSource("d:\\mail.gif");
    MimeBodyPart mimeAttach=new MimeBodyPart();
    mimeAttach.setDataHandler(new DataHandler(fds));
    mimeAttach.setFileName(fds.getName());
    mailBody.addBodyPart(mimeAttach);
    msg.setContent(mailBody);
                               ////
    Transport.send(msg);

    }
    catch(MessagingException mex){ 
    mex.printStackTrace(); 
    //System.out.println("can't send mail");
    }

    } //end main()


    class MailAuthenticator extends Authenticator
    {
    private String UserName;
    private String Password;
    public MailAuthenticator(String UserName,String Password)
    {
    this.UserName = UserName;
    this.Password = Password;
    } public PasswordAuthentication getPasswordAuthentication()
    {
    return new PasswordAuthentication(this.UserName,this.Password);
    }
    }
    ----------
    好像只有sina的信箱可以使用本程序,sohu和hotmail等都不可以
      

  3.   

    String host="smtp.yourservername";
      

  4.   

    这里不对(值得商讨):
    String from = "[email protected]"; //可随便写很多都要求论证,只有用户名与之相对且密码正确才能够发得出去,不然会报没有权限的错这里也有不应对:
    String host = "smtp.sina.com.cn"; //或者host="202.106.187.180";都可用
    只能用前一种即 smtp.sina.com.cn,而不能用IP,202.106.187.180
    所以你的错误也就是不应该用的IP,而用我上面提到的方法
    smtp.yourservername
      

  5.   

    to netkill(网络天使)
    我做过测试啊,用ip可以的