indent -kr -i4   SimpleMail.java 可以用,但是太简单

astyle 这个工具不错

http://astyle.sourceforge.net/

astyle --style=java --style=allman   -f  SimpleMail.java

发送邮件的java代码!!亲测可以用

import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication; import java.util.Properties; public class SimpleMail
{ private static final String SMTP_HOST_NAME = "smtp.host.com";
private static final String SMTP_AUTH_USER = "no-replay@xxxx.com";
private static final String SMTP_AUTH_PWD = "password"; public static void main(String[]args) throws Exception
{
new SimpleMail().test();
}
public void test() throws Exception
{
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true"); Authenticator auth = new SMTPAuthenticator();
Session mailSession = Session.getDefaultInstance(props, auth); // uncomment for debugging infos to stdout
// mailSession.setDebug(true);
Transport transport = mailSession.getTransport(); MimeMessage message = new MimeMessage(mailSession);
message.setContent("This is a test", "text/plain");
message.setFrom(new InternetAddress("xxx.com"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress("12354656@qq.com")); transport.connect();
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();
}
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}
}
}

  

最新文章

  1. C# salt+hash 加密
  2. [deviceone开发]-do_Album的简单示例
  3. angular.js中插值语法和ng-bind以及ng-model的区别
  4. html5 上传头像的裁剪
  5. 『TCP/IP详解——卷一:协议』读书笔记——18
  6. sleep() 和 wait() 的区别
  7. 在SecureCRT中使用rz和sz传输文件
  8. 通过 Chrome Workspace 调试本地项目(修改样式时及时保存)
  9. iOS开发——汉字转拼音
  10. Windows 10 IoT Core环境配置中的那些坑
  11. Jlink下载问题
  12. RPC架构简单理解
  13. 微信公众号开发C#系列-6、消息管理-普通消息接受处理
  14. DSAPI 网卡流量监控
  15. AI之旅(3):升维与最小二乘法
  16. 玩转Python图片处理 (OpenCV-Python )
  17. iReport 5.6.0 组件面板为空 get小技巧
  18. DAY65
  19. PHP代码审计笔记--变量覆盖漏洞
  20. linux下getsockopt和setsockopt详解及测试

热门文章

  1. Vue.js中学习使用Vuex详解
  2. C# 工厂单例
  3. linux 怎么在后台添加运行脚本,即使关机也可以用
  4. Linux下MySql数据的导入导出
  5. android GPS 定位,取位置信息
  6. MVC系列学习(零)-本次学习可能会遇到的问题汇总
  7. JS高级——Function原型链
  8. CSS——行高
  9. k[原创]Faster R-CNN论文翻译
  10. LINUX - 硬链接 软连接