jodd mail技术实现简单发送email邮件

maven 依赖

        <dependency>
            <groupId>org.jodd</groupId>
            <artifactId>jodd-mail</artifactId>
            <version>3.7</version>
        </dependency>

java jodd mail 用到的jar包下载地址

程序

package com.mail.test;

import jodd.mail.*;
import org.junit.Test;

import java.io.File;

/**
 * Created by simon on 2016/4/20.
 */
public class test {

//支持html页面展示
    public static void main(String args[]){
        String [] emails={"目标邮箱2","目标邮箱1"};
        SmtpServer<?> smtp = SmtpSslServer.create("你的SSL的smtp服务器",465);//设置SSL的smtp服务器,我的,smtp.mxhichina.com
        smtp.authenticateWith("你的smtp邮箱", "你的密码");//我的,service@www.dtxzw.com,密码省略....
        SendMailSession session = smtp.createSession();
        Email email = Email.create().from("你的smtp邮箱").subject("邮件标题")//设置了主题
                .to(emails)
                .addHtml("<p style='background:green'>html的文件内容!</p>")
                ;
        session.open();//打开连接
        session.sendMail(email);//发送邮件
        session.close();//关闭连接
        System.out.println("发送成功");
    }
    //支付多附件
//    public static  void main(String ss[]) throws IOException {
//        sendMail("zhangxiangfeng@sudaotech.com","/home/simon/桌面/cwch824.2/cwch/WebRoot/download/yingyu/英语选修6电子档.pdf");
//    }

    public static void sendMail(String mail,String filePath) throws IOException {

        EmailAttachment attachment = new FileAttachment(
                new File(filePath), "考的好.pdf", "pdf");

        String [] emails={mail};
        SmtpServer<?> smtp = SmtpSslServer.create("smtp.mxhichina.com",465);
        smtp.authenticateWith("kaodehao@www.dtxzw.com", "****");
        SendMailSession session = smtp.createSession();
        Email email = Email.create().from("kaodehao@www.dtxzw.com").subject("考的好系统邮件")
                .to(emails).attach(attachment)
                .addText("你好,你下载的内容在附件里面")
                ;
        session.open();//打开连接
        session.sendMail(email);//发送邮件
        session.close();//关闭连接
        System.out.println("发送邮件成功");
    }
}

亲测可用,不懂可追问。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一缕阳光直射你的心扉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值