⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailsender.sql

📁 用来JAVA存储过程在ORACLE9I或者10G里面发邮件的例子
💻 SQL
字号:
create or replace and compile java source named mailsender as
import java.io.File;
import java.io.PrintWriter;
import java.sql.*;
import java.util.*;

/**
 * @author junsansi
 * @qq 5454589
 * @website www.5ienet.com
 */

public class MailSender {
    //ishtml  1是 0否
    public static MailService ms = null;

    /**
     * initialize mailService
     * @throws Exception
     */
    void init() throws Exception {
        ms = new MailService("smtp.sina.com.cn");  //smtp地址

        try {
            ms.setFrom("junsansi@sina.com");  //发送邮箱(不重要,只是显示)
            ms.setUserName("junsansi@sina.com");  //邮箱帐号
            ms.setPassword("123456");  //输入你的邮箱密码,呵呵,此处是我瞎写,您就表尝试用这个登陆了
            ms.setSmtpAuth(true);
        } catch (Exception e) {
            throw e;
        }
    }

    /**
     * sendmail no attachment
     * @param to String
     * @param sendTopic String
     * @param sendContent String
     * @param ishtml int
     * @return String
     */
    public static String send(String to, String sendTopic,
                              String sendContent, int ishtml) {
        return send(to, null, null, sendTopic, sendContent, null, ishtml);
    }

    /**
     * sendmail by attachment
     * @param to String
     * @param sendTopic String
     * @param sendContent String
     * @param filename String
     * @param ishtml int
     * @return String
     */
    public static String send(String to, String sendTopic,
                              String sendContent, String filename, int ishtml) {
        return send(to, null, null, sendTopic, sendContent, filename, ishtml);
    }

    /**
     * sendmail by cc,bcc but no attachment
     * @param to String
     * @param cc String
     * @param bcc String
     * @param sendTopic String
     * @param sendContent String
     * @param ishtml int
     * @return String
     */
    public static String send(String to, String cc, String bcc,
                              String sendTopic,
                              String sendContent, int ishtml) {
        return send(to, cc, bcc, sendTopic, sendContent, null, ishtml);
    }

    /**
     * sendmail by cc,bcc and attachment
     * @param to String
     * @param cc String
     * @param bcc String
     * @param sendTopic String
     * @param sendContent String
     * @param filename String
     * @param ishtml int
     * @return String
     */
    public static String send(String to, String cc, String bcc,
                              String sendTopic,
                              String sendContent, String filename, int ishtml) {
        MailSender makeSta = new MailSender();
        String result = null;
        try {
            if (ms == null) {      //调试smtp服务器的时候,将本段if去掉,只保留makeSta.init();不然修改过后也不会被编译
                makeSta.init();
            }
            ms.setTo(to);
            if (cc != null ) {
                cc = cc.trim();
                if (cc.length() > 0){
                    String[] cclist = split(cc, ",");

                    Vector list = new Vector(cclist.length);
                    int i;
                    for (i = 0; i < cclist.length; i++) {
                        list.add(cclist[i]);
                    }
                    ms.setCc(list);
                }
            }
            if (bcc != null) {
                bcc = bcc.trim();
                if (bcc.length() > 0){
                    String[] bcclist = split(bcc, ",");
                    Vector list = new Vector(bcclist.length);
                    int i;
                    for (i = 0; i < bcclist.length; i++) {
                        list.add(bcclist[i]);
                    }
                    ms.setBcc(list);
                }
            }
            if (filename != null) {
                filename = filename.trim();
                if (filename.length() > 0){
                    ms.setFilename(filename);
                }
            }

            ms.setSubject(sendTopic);
            if (ms.send(sendContent, ishtml)) {
                result = "successed to sent the mail to " + to;
            } else {
                result = "Failed to sent the mail.";
            }

        } catch (Exception e) {
          e.printStackTrace();
            result = "Failed to sent the mail, err:" + e.getMessage();
        } finally {
            return result;
        }

    }

    /**
     * no split function in java.lang.String in jdk1.3
     * so,i have write on by my self.
     * @param strtxt String
     * @param key String
     * @return String[]
     */
    public static String[] split(String strtxt, String key) {
        StringTokenizer st = new StringTokenizer(strtxt, key);
        ArrayList al = new ArrayList();

        while (st.hasMoreTokens()) {
            al.add(st.nextToken());
        }
        String[] result = new String[al.size()];
        al.toArray(result);

        return result;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -