代码拉取完成,页面将自动刷新
同步操作将从 AnotherWay/oh-my-email 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
A permissive license whose main conditions require preservation of copyright and license notices. Contributors provide an express grant of patent rights. Licensed works, modifications, and larger works may be distributed under different terms and without source code.
或许是最小的 Java 邮件发送类库了。
maven坐标
<dependency>
<groupId>io.github.biezhi</groupId>
<artifactId>oh-my-email</artifactId>
<version>0.0.4</version>
</dependency>
@Before
public void before() throws GeneralSecurityException {
// 配置,一次即可
OhMyEmail.config(SMTP_QQ(), "xiaojiejie@qq.com", "your@password");
}
@Test
public void testSendText() throws MessagingException {
OhMyEmail.subject("这是一封测试TEXT邮件")
.from("小姐姐的邮箱")
.to("xiaojiejie@gmail.com")
.text("信件内容")
.send();
}
@Test
public void testSendHtml() throws MessagingException {
OhMyEmail.subject("这是一封测试HTML邮件")
.from("小姐姐的邮箱")
.to("xiaojiejie@gmail.com")
.html("<h1 font=red>信件内容</h1>")
.send();
}
@Test
public void testSendAttach() throws MessagingException {
OhMyEmail.subject("这是一封测试附件邮件")
.from("小姐姐的邮箱")
.to("xiaojiejie@gmail.com")
.html("<h1 font=red>信件内容</h1>")
.attach(new File("/Users/biezhi/Downloads/hello.jpeg"), "测试图片.jpeg")
.send();
}
@Test
public void testSendAttachURL() throws MessagingException {
try {
OhMyEmail.subject("这是一封测试网络资源作为附件的邮件")
.from("小姐姐的邮箱")
.to("xiaojiejie@gmail.com")
.html("<h1 font=red>信件内容</h1>")
.attachURL(new URL("https://avatars1.githubusercontent.com/u/2784452?s=40&v=4"), "测试图片.jpeg")
.send();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Test
public void testPebble() throws IOException, PebbleException, MessagingException {
PebbleEngine engine = new PebbleEngine.Builder().build();
PebbleTemplate compiledTemplate = engine.getTemplate("register.html");
Map<String, Object> context = new HashMap<String, Object>();
context.put("username", "biezhi");
context.put("email", "admin@biezhi.me");
Writer writer = new StringWriter();
compiledTemplate.evaluate(writer, context);
String output = writer.toString();
System.out.println(output);
OhMyEmail.subject("这是一封测试Pebble模板邮件")
.from("小姐姐的邮箱")
.to("xiaojiejie@gmail.com")
.html(output)
.send();
}
@Test
public void testJetx() throws IOException, PebbleException, MessagingException {
JetEngine engine = JetEngine.create();
JetTemplate template = engine.getTemplate("/register.jetx");
Map<String, Object> context = new HashMap<String, Object>();
context.put("username", "biezhi");
context.put("email", "admin@biezhi.me");
context.put("url", "<a href='http://biezhi.me'>https://biezhi.me/active/asdkjajdasjdkaweoi</a>");
StringWriter writer = new StringWriter();
template.render(context, writer);
String output = writer.toString();
System.out.println(output);
OhMyEmail.subject("这是一封测试Jetx模板邮件")
.from("小姐姐的邮箱")
.to("xiaojiejie@gmail.com")
.html(output)
.send();
}
<div>
<p>亲爱的<b>{{ username }}</b>, 欢迎加入 biezhi !</p>
<p>当您收到这封信的时候,您已经可以正常登录了。</p>
<p>请点击链接登录首页: <a href='http://www.baidu.com'>http://biezhi.me/xxxxx</a></p>
<p>如果您的 email 程序不支持链接点击,请将上面的地址拷贝至您的浏览器(如IE)的地址栏进入。</p>
<p>如果您还想申请管理员权限,可以联系管理员 {{ email }}</p>
<p>我们对您产生的不便,深表歉意。</p>
<p>希望您在 biezhi 系统度过快乐的时光!</p>
<p></p>
<p>-----------------------</p>
<p></p>
<p>(这是一封自动产生的email,请勿回复。)</p>
</div>
biezhi.me#gmail.com
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。