zoukankan      html  css  js  c++  java
  • 发送一封简单的邮件

         

    MimeMessage message = null; final Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.socketFactory.fallback", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", port); props.put("mail.user", user); props.put("mail.password", pw); Authenticator authenticator = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication(){ String userName = props.getProperty("mail.user"); String password = props.getProperty("mail.password"); return new PasswordAuthentication(userName, password); } }; Session mailSession = Session.getInstance(props, authenticator); message = new MimeMessage(mailSession); message.setFrom(new InternetAddress("邮箱地址", "邮箱名称", "UTF-8")); //1、是否需要回执--非必须 message.setHeader("Disposition-Notification-To", "<gyli1992@qq.com>"); //收件人地址 message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("gyoyinli1992@qq.com", "user_to", "UTF-8")); //主题 message.setSubject("test02"); //内容 message.setContent("<a href='taoquan.tlong.top' style='color:#ccc'>淘券网</a>", "text/html;charset=UTF-8"); //显示发送时间 message.setSentDate(new Date()); //保存更改 message.saveChanges(); //输出eml文件 OutputStream out = new FileOutputStream("D://myemail.eml"); message.writeTo(out); out.flush(); out.close(); //发送邮件 Transport.send(message); System.out.println("邮件发送成功");
  • 相关阅读:
    oracle 如何用触发器实现更新刚插入的数据
    数据库好论坛
    不同的用户导入数据库
    用函数式编程技术编写优美的 JavaScript
    使用GridView自带的ToolTip隐藏过长的数据
    含有dropdownlist的gridview增删改查
    数据分析
    数据分析
    xshell链接vbox 上 nat 方式链接虚拟机
    测试开发方法概述
  • 原文地址:https://www.cnblogs.com/guoyinli/p/8303485.html
Copyright © 2011-2022 走看看