JavaMail 在服务器2003上发送不了邮件

private void sendMail(Hashtable gz){
        String m_strContent = "<p><table><tr><td>Hello javaMail and test example!</td></tr></table></p>";
        Properties provs = new Properties();
        Authenticator auth = new MyAuthenticator(username,password);
        provs.put("mail.smtp.host", host);
        provs.put("mail.smtp.auth", "true");
        provs.put("mail.transport.protocol", "smtp");
        provs.put("mail.smtp.port", "25");
        Session session = Session.getDefaultInstance(provs,null);
        session.setDebug(true);
        MimeMessage message = new MimeMessage(session);
        try {
            message.setSubject("test javaMail");//jtfsubject.getText()
            message.setSentDate(new Date());
            message.setContext("Test Mail","text/html");

        } catch (IOException ex) {
            Logger.getLogger(TestSendMail.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MessagingException ex) {
            Logger.getLogger(TestSendMail.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            Address toAddress = new InternetAddress(mailAddress);//yuping159@gmail.com
            Address fromAddress = new InternetAddress("87523774@qq.com");
            Address reply = new InternetAddress("56545465@qq.com");
            message.setReplyTo(new Address[]{reply});
    
            message.setFrom(fromAddress);
            message.setRecipients(RecipientType.TO, new Address[]{toAddress});
            message.saveChanges(); // implicit with send()
           Transport transport = session.getTransport("smtp");
            transport.connect(host, username, password);
            transport.sendMessage(message, message.getAllRecipients());
            transport.close();
        }catch(AuthenticationFailedException e){
            JOptionPane.showMessageDialog(null, "密码错误");
        } catch (AddressException ex) {
            Logger.getLogger(TestSendMail.class.getName()).log(Level.SEVERE, null, ex);
        } catch(SMTPSendFailedException e){
            JOptionPane.showMessageDialog(null, "邮件发送失败");
        } catch (MessagingException ex) {
            Logger.getLogger(TestSendMail.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

 

 

 

以上代码是使用javaMail发送邮件的,在本地测试通过,可以发送邮件,但是到2003服务器上就不行了,本人不清楚,这个smtp服务一定要开通吗,或者说和2003系统有哪些问题?2003系统没有打sp2补丁包,IIS服务中没有选择安装smtp Service这服务。

 

本人做的测试是,在本人的机器xp上,即使把smtp Service 服务部打钩,重新配置IIS,还是可以发送smtp邮件.

 

请问大侠,请提供思路,问题有可能出现在哪里?

本人QQ:87523774;

万分感谢!!!!!!!

 

补充说明,和代码没有什么联系,应该重smtp服务的环境考虑。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Java中使用JavaMail库匿名发送邮件,你可以按照以下步骤进行操作: 1. 首先,确保你已经导入了javamail库。你可以在Maven项目中添加以下依赖项: ```xml <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> <version>1.6.2</version> </dependency> ``` 2. 创建一个`Properties`对象来配置SMTP服务器的连接属性。设置SMTP服务器的主机名和端口号,以及启用SSL加密(如果需要): ```java Properties properties = new Properties(); properties.put("mail.smtp.host", "your_smtp_host"); properties.put("mail.smtp.port", "your_smtp_port"); properties.put("mail.smtp.ssl.enable", "true"); // 如果需要加密,将其设置为"true" ``` 3. 创建一个`Session`对象,用于建立与SMTP服务器的连接。在创建`Session`对象时,可以通过传递`Authenticator`对象来实现匿名发送邮件: ```java Session session = Session.getInstance(properties, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("", ""); // 空的用户名和密码 } }); ``` 4. 创建一个`Message`对象,用于构造邮件。设置发件人、收件人、主题和内容等信息: ```java Message message = new MimeMessage(session); message.setFrom(new InternetAddress("sender@example.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient@example.com")); message.setSubject("Hello, World!"); message.setText("This is the content of the email."); ``` 5. 使用`Transport`类发送邮件: ```java Transport.send(message); ``` 这样,你就可以使用JavaMail库在内网中匿名发送邮件了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值