当前位置:编程学习 > JSP >>

一段带smtp认证的JavaMail代码。

        Properties props = System.getProperties();
        props.put("mail.smtp.host", host);
        String mailNeedAuth = CatseyeConfig.getConfig("MailNeedAuth");
        String mailUser = CatseyeConfig.getConfig("MailUser");
        String mailPassword = CatseyeConfig.getConfig("MailPassword");
        if (mailNeedAuth.equals("1")) {
            props.put("mail.smtp.auth", "true");
        } else {
            props.put("mail.smtp.auth", "false");
        }
        Session session = Session.getDefaultInstance(props, null);
        javax.mail.Message msg = new MimeMessage(session);
        InternetAddress[] toAddrs = null;
        try {
            if (recipients != null) {
                toAddrs = InternetAddress.parse(recipients, false);
                msg.setRecipients(javax.mail.Message.RecipientType.TO, toAddrs);
            } else {
                throw new Exception("No recipient address specified");
补充:Jsp教程,邮件
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,