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

📄 sendmail.java

📁 java版的发送电子邮件组件
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SendMail.java

package dispose;

import com.zyf.tools.GetPath;
import com.zyf.tools.connectdb.DBOS;
import com.zyf.tools.mail.MailAuthenticator;
import java.io.*;
import java.sql.ResultSet;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;

public class SendMail
{

    public String smtpHost;
    public String from;
    public String to;
    public String subject;
    public String mailContent;
    public String mailContentType;
    public Properties props;
    public Session mailSession;
    public Message message;

    public SendMail()
        throws Exception
    {
        Properties properties = new Properties();
        properties = GetPath.getPath("SendMail.ini");
        smtpHost = properties.getProperty("SMTPHOST");
        props = System.getProperties();
        props.put("mailsmtp.host", smtpHost);
        props.put("mailsmtp.auth", "true");
        mailSession = Session.getInstance(props, new MailAuthenticator());
        message = new MimeMessage(mailSession);
    }

    public void mailInit()
        throws Exception
    {
    }

    public void setFrom(String s)
        throws Exception
    {
        from = s;
        message.setFrom(new InternetAddress(from));
    }

    public void setTo(String s)
        throws Exception
    {
        to = s;
        message.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
    }

    public void setSubject(String s)
        throws Exception
    {
        subject = s;
        message.setSubject(subject);
    }

    public void setMailContent(String s, String s1)
        throws Exception
    {
        mailContent = s;
        mailContentType = s1;
        message.setContent(mailContent, mailContentType);
    }

    public void sendMail()
        throws Exception
    {
        Transport.send(message);
    }

    public boolean sendMail(PageContext pagecontext, String s)
        throws Exception
    {
        DBOS dbos = new DBOS();
        try
        {
            String s1 = "select * from Notice_Content where noticeID='" + s + "'";
            dbos.execute(s1);
            if(dbos.result.next())
            {
                setSubject(dbos.result.getString("title"));
                String s2 = dbos.result.getString("content");
                MimeMultipart mimemultipart = new MimeMultipart();
                MimeBodyPart mimebodypart = new MimeBodyPart();
                mimebodypart.setContent(s2, "text/html;charset=Gb2312");
                mimemultipart.addBodyPart(mimebodypart);
                String s3 = "select * from Notice_Accessories where noticeID='" + s + "'";
                dbos.execute(s3);
                for(int i = 0; dbos.result.next(); i++)
                {
                    byte abyte0[] = dbos.result.getBytes("accessoriesData");
                    String s4 = dbos.result.getString("accessoriesName");
                    String s5 = s4.substring(s4.lastIndexOf("."), s4.length());
                    String s6 = pagecontext.getSession().getId();
                    String s7 = "/Tomcat/webapps/ROOT/" + s6 + s5;
                    FileOutputStream fileoutputstream = new FileOutputStream(s7);
                    fileoutputstream.write(abyte0);
                    fileoutputstream.close();
                    File file = new File(s7);
                    FileDataSource filedatasource = new FileDataSource(file);
                    MimeBodyPart mimebodypart1 = new MimeBodyPart();
                    mimebodypart1.setDataHandler(new DataHandler(filedatasource));
                    String s8 = "accessories" + i + s5;
                    mimebodypart1.setFileName(s8);
                    mimemultipart.addBodyPart(mimebodypart1);
                }

                message.setContent(mimemultipart);
                System.out.println("aa");
                Transport.send(message);
            }
        }
        catch(Exception exception)
        {
            throw exception;
        }
        finally
        {
            dbos.releaseResource();
        }
        return true;
    }
}

⌨️ 快捷键说明

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