java邮件发送,批量发送(.xml文件中配置)

声明:涉及到spring的bean加载的内容,这里不做叙述。

一、实现邮件发送之前,现在.xml文件中进行配置:

2种方式:(1)QQ邮箱:

<bean id="sm" class="cn.redinfo.jlxh.manager.bean.SendMail">
    <property name="host" value="smtp.exmail.qq.com" />
    <property name="port" value="25" />
    <property name="address" value="123456789@qq.com" />
    <property name="password" value="2017" />
</bean>

(2)其他邮箱发送:

<bean id="sm" class="simple.threads.SendMail">
     <property name="host" value="smtp.163.com" />
     <property name="port" value="25" />
     <property name="address" value="666666@163.com" />
     <property name="password" value="123456" />
</bean>
 //定时发送   
<bean id="dataThread2" class="simple.threads.ScannCheckStatusThread" factory-method="getInstance" init-method="init">
     <property name="sendMail" ref="sm"/>
     <property name="startTime" value="22:00:00" />      //每天晚上10整
     <property name="nextTime" value="24*60*60*1000" />  //每隔一天发送一次
</bean>

host=smtp.ym.163.com

 

java中实现邮件的发送:

/**
 * 线程:发送提醒邮件
 * 
 * @author Administrator
 * 
 */
public class SendMail {
    private String host;
    private String port;
    private String address;
    private String password;

    public void process(String mailContent, String receiveAddress) {
        try {
            MailSenderInfo mailInfo = new MailSenderInfo(); //自己封装的类
            mailInfo.setMailServerHost(this.host);
            mailInfo.setMailServerPort(this.port);
            mailInfo.setValidate(true);
            mailInfo.setUserName(this.address);
            mailInfo.setPassword(this.password);// 您的邮箱密码
            mailInfo.setFromAddress(this.address);
            mailInfo.setSubject("发送通知");
            
            SimpleMailSender sms = new SimpleMailSender();  //自己封装的类
            mailInfo.setToAddress(receiveAddress);
            mailInfo.setContent(mailContent);
            sms.sendTextMail(mailInfo);// 发送文体格式
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public String getHost() {
        return host;
    }
    public void setHost(String host) {
        this.host = host;
    }
    public String getPort() {
        return port;
    }
    public void setPort(String port) {
        this.port = port;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}

实际应用:

StringBuffer sb = new StringBuffer();
sb.append("您好:"+"\n"); sb.append(" 您报名参加的专业的培训班已经开班,现将培训通知发给您,请按时报到。\n"); sb.append(" 培训部025-88888888"); SendMail send = new SendMail();
send.process(sb.toString(), "6666666@qq.com");  //发送邮件提醒

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值