| | |
| | | } |
| | | |
| | | /** |
| | | * 创建邮件内容 需科学上网 |
| | | * 创建邮件内容 |
| | | * |
| | | * @param sentToEmail 接收人邮箱 |
| | | * @param subject 设置邮件主题 |
| | | * @param content 内容 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static boolean getMimeMessage(String sentToEmail, String subject, String content) throws Exception { |
| | | public static boolean send(String sentToEmail, String subject, String content) throws Exception { |
| | | //1.创建一封邮件的实例对象 |
| | | Properties props = new Properties(); |
| | | //选择ssl方式 |
| | | gmailssl(props); |
| | | |
| | | final String username = "southwindservice@gmail.com";// gmail 邮箱 |
| | | final String password = "irkgrsuzxgmwrxzy";// Google应用专用密码 |
| | | final String password = "ogsntijmguisoiuk";// Google应用专用密码 |
| | | // 当做多商户的时候需要使用getInstance, 如果只是一个邮箱发送的话就用getDefaultInstance |
| | | // Session.getDefaultInstance 会将username,password保存在session会话中 |
| | | // Session.getInstance 不进行保存 |
| | |
| | | |
| | | Transport.send(msg); |
| | | return true; |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | boolean mimeMessage = getMimeMessage("393733352@qq.com", "测试内容", "这是一段测试内容"); |
| | | System.out.println(mimeMessage); |
| | | } |
| | | } |