An open API service indexing awesome lists of open source software.

https://github.com/aowubulao/neo-mail

一个简单的Java mail 邮件库,支持抄送、密送、Html邮件等功能
https://github.com/aowubulao/neo-mail

java mail

Last synced: 6 months ago
JSON representation

一个简单的Java mail 邮件库,支持抄送、密送、Html邮件等功能

Awesome Lists containing this project

README

          

# Neo-Mail

一个学习性质的邮件库。

支持群发,抄送、密送。支持发送Html及Html模板的邮件。

基于Socket套接字编写,简洁、运行速度快。

## 快速开始

**· Maven坐标**

```

com.neoniou
neo-mail
1.0.1

```

**· 使用实例**

```java
/**
* 可以通过 properties文件读取配置
*/
@Before
public void readConfig() {
Properties props = new Properties();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("mail.properties");
try {
props.load(is);
username = props.getProperty("username");
password = props.getProperty("password");
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* 发送简单文本邮件
*/
@Test
public void sendTextTest() {
NeoMail neoMail = new NeoMail();
try {
neoMail.config(MailSmtp.QQ, username, password)
.subject("这是一封测试简单文本邮件")
.from("Neo")
.to("me@neow.cc")
.text("这是内容")
.send();
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* 发送简单 Html邮件
*/
@Test
public void sendHtmlTest() {
NeoMail neoMail = new NeoMail();
try {
neoMail.config(MailSmtp.QQ, username, password)
.subject("这是一封测试简单Html邮件")
.from("Neo")
.to("me@neow.cc")
.html("

标题

内容
")
.send();
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* 发送 Pebble模板的 Html邮件
*/
@Test
public void sendPebbleTest() {
NeoMail neoMail = new NeoMail();
try {
//使用 Pebble
PebbleEngine engine = new PebbleEngine.Builder().build();
PebbleTemplate compiledTemplate = engine.getTemplate("test.html");

Map context = new HashMap();
context.put("number", "1234");

Writer writer = new StringWriter();
compiledTemplate.evaluate(writer, context);

String html = writer.toString();

//发送邮件
neoMail.config(MailSmtp.QQ, username, password)
.subject("这是一封测试Pebble邮件")
.from("Neo")
.to("me@neow.cc")
.html(html)
.send();
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* 群发邮件,包括抄送和密送
*/
@Test
public void sendCcAndBccTest() {
NeoMail neoMail = new NeoMail();
try {
neoMail.config(MailSmtp.QQ, username, password)
.subject("这是一封测试抄送密送的邮件")
.from("Neo")
.to("mail1", "mail2")
.cc("mail3", "mail4")
.bcc("mail5", "mail6")
.text("这是内容")
.send();
} catch (IOException e) {
e.printStackTrace();
}
}
```

### Pebble中的test.html

```html


这是一封测试Html的邮件



如果你能顺利地看到数字:{{ number }}


那么表示程序成功运行了

```