javamail发邮件如何实现不用用户名和密码请各位高手给个源码看看

解决方案 »

  1.   

    Properties props = new Properties();
    props.put("mail.smtp.auth","false");
    设置成false就不需要认证了,网上很多例子的,google一下,呵呵
      

  2.   

    哦,好的,。我的邮箱是 [email protected]  谢谢啊
      

  3.   

    /*
       * 用你自己的mailserver啊,在配置文件中写好
       * 用户名、密码、邮件服务器,程序中读取出来
       * 然后调用sendAttach方法就行啦。
       */
      private static String host = Properties.getSystemProperty("mail.server");
    private static String user = Properties.getSystemProperty("mail.server.user");
    private static String password = Properties.getSystemProperty("mail.server.password");/**
     * @from:发件人
     * @to:  收件人
     * @subject:邮件标题
     * @subject:邮件内容
     * @fileName:附件
     */ 
    public static void sendAttach(String from, String to, String subject, String content, String fileName) {
    Properties props = new Properties();
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.auth", "true");
    if (from == null || from.trim().length() == 0) {
    from = systemEmail;
    }
    try {
    Session mailSession = Session.getDefaultInstance(props);
    mailSession.setDebug(true);
    Message message = new MimeMessage(mailSession);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setContent(content, "text/html;charset=GB2312");
    // attached
    Date now = new Date();
    long name = now.getTime();
    BodyPart messageBodyPart2 = new MimeBodyPart();
    messageBodyPart2.setFileName(name + "");
    FileDataSource fileDataSource = new FileDataSource(fileName);
    messageBodyPart2.setDataHandler(new DataHandler(fileDataSource));
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    multipart.addBodyPart(messageBodyPart2);
    message.setContent(multipart);
    message.saveChanges();
    Transport transport = mailSession.getTransport("smtp");
    transport.connect(host, user, password);
    transport.sendMessage(message, message.getAllRecipients());
    transport.close();
    }
    catch (Exception e) {
    System.out.println(e);
    }
    }***************************************************************
    做个广告^_^:欢迎加入我刚建立的群组:http://group.csdn.net/qwert
    ***************************************************************
      

  4.   

    上面是带附件的方法,不带附件用:
    public static void send(String from, String to, String subject, String content) {
    Properties props = new Properties();
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.auth", "true");
    if (from == null || from.trim().length() == 0) {
    from = systemEmail;
    }
    try {
    MailAuthenticator myauth = new MailAuthenticator(user, password);
    Session mailSession = Session.getInstance(props, myauth);
    mailSession.setDebug(true);
    Message message = new MimeMessage(mailSession);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);
    message.setText(content);
    message.saveChanges();
    Transport transport = mailSession.getTransport("smtp");
    transport.connect(host, user, password);
    transport.sendMessage(message, message.getAllRecipients());
    transport.close();
    }
    catch (Exception e) {
    System.out.println(e);
    }
    }
      

  5.   

    jr_zhang(梅川内酷) MailAuthenticator myauth = new MailAuthenticator(user, password);
    这个类怎么写啊
      

  6.   

    class MailAuthenticator extends Authenticator {
            private String strUser;
            private String strPwd;
            public MailAuthenticator(String user, String password) {
                    this.strUser = user;
                    this.strPwd = password;
            }
      

  7.   

    这个不行的吧,SMTP协议现在规定没有用户名密码不让乱发,是防垃圾邮件吧
      

  8.   

    上面的例子比较详细了。
    首先要你的邮件服务器的协议中支持不认证的方式,也就是不使用User+pass的方式登录发Mail。
    然后程序中才可以使用 不认证的方式。
      

  9.   

    简单邮件
    <a href="mailto:[email protected]?subject=ccc&body=xxxyyy">  
      

  10.   

    当然可以不用帐号密码发邮件啦,不知各位是否用过类似邮件直投的软件。
    你也可以想想各个邮件服务器之间是如何投递邮件的,所以邮件直投是可以的
    先要通过dns协议获取要发送的目的邮箱的MX邮箱名,然后就可以通过SMTP向目的邮箱发送
    可以看看俺做的邮件直投工具,地址http://yycnet.yeah.net 下载专区Ymailer
      

  11.   

    yyc_csdn
     
    (yyc) 你那给的不是网易的邮箱地址么?
    你能给出具体代码吗