import java.util.Properties;

 import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType; public class MailUtils {
private static String smtp_host = "smtp.126.com";
private static String username = "itcast_server@126.com";
private static String password = "147963qP"; private static String from = "itcast_server@126.com"; // 使用当前账户
public static String activeUrl = "http://localhost:8082/bos_fore/customerAction_activeMail"; public static void sendMail(String subject, String content, String to) {
Properties props = new Properties();
props.setProperty("mail.smtp.host", smtp_host);
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.auth", "true");
Session session = Session.getInstance(props);
Message message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(from));
message.setRecipient(RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
message.setContent(content, "text/html;charset=utf-8");
Transport transport = session.getTransport();
transport.connect(smtp_host, username, password);
transport.sendMessage(message, message.getAllRecipients());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("邮件发送失败...");
}
} public static void main(String[] args) {
sendMail("测试邮件", "你好,大神", "itcast_search@163.com");
}
}

MailUtils 测试邮件是否发送的更多相关文章

  1. 利用工具MailUtils实现邮件的发送,遇到的大坑,高能预警!!

    java实现邮件的发送依赖的jar包有两个:mail.jar和activation.jar,我也找到了一个工具包:itcast-tools-1.4.jar,实现原理大家可以查看源码,先放出资源链接 h ...

  2. C#中邮件的发送基本操作

    本地配置的邮箱:http://localhost:6080/index.php //邮件的收发需要用到两个类   //1.用来创建一封邮件对象     //1.MailMessage 添加对 usin ...

  3. jenkins构建邮件自动发送,测试邮件发送成功,构建项目邮件发送不成功的问题

    提示问题: Connection error sending email,retrying once more in 10 seconds…… Connection error sending ema ...

  4. 使用Gerrit发送测试邮件

    使用Gerrit发送测试邮件 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装HTTP服务 1>.安装HTTP服务 [root@gerrit.yinzhengjie.o ...

  5. wordpress发送测试邮件

    下面的邮箱设置使用了qq邮箱的设置 写上接收测试邮件的邮箱  再send test

  6. python测试开发django-29.发送html格式邮件

    前言 上一篇已经通过send_mail()函数发送纯文本的邮件,发送成功了,如果我们想发送一个html格式的邮件,如何实现呢? 发送html格式的邮件实际上还是调用send_mail()函数 ,只需多 ...

  7. Activation successful 数据库邮件无法发送

    问题现象: 配置好数据库邮件后发送测试邮件. 在数据库邮件发送日志中显示状态为:Activation successful.而邮件是无法收到的. 解决方法: 本次解决是将SQL Server Agen ...

  8. 怎么使用PHPMailer实现邮件的发送??

    来源:http://www.ido321.com/1103.html 发送邮件是常用的功能,LZ今天在项目中也碰到了,特此分享一下. 首先,去下载PHPMailer 1.https://github. ...

  9. 01_JavaMail_04_带附件邮件的发送

    [工程截图] [代码实例] package com.Higgin.mail.demo; import java.io.File; import java.util.Properties; import ...

随机推荐

  1. 2015-03-20——移动端UC浏览器、QQ浏览器自动全屏

    UC:<meta name="full-screen" content="yes"><meta name="browsermode& ...

  2. Learn How To Cross Over The Wall

    1.一个proxy的实现 http://blog.codingnow.com/2011/05/xtunnel.html 2.SOCK5 RFC http://www.faqs.org/rfcs/rfc ...

  3. 解决127.0.0.1 localhost 劫持问题

    在一个安装iis的过程中,把网站部署上去之后就发现127.0.0.1或者localhost都会跳转到一个莫名的网站,发现断网之后就是会跳转到一个Http://www.76636.com 类似这种的网站 ...

  4. React官网首页demo(单文件实现版)

    本博客实现React官网首页上展示的demo, 为了方便直接采用单文件的形式, 如果想完整集成 在自己的项目中, 可以参考React官网的安装指南, 安装Create React App. hello ...

  5. ceshi1

    图片素材

  6. Read Large Files in Python

    I have a large file ( ~4G) to process in Python. I wonder whether it is OK to "read" such ...

  7. 数据库权限分配(远程共享数据库)(mysql)

    1. 数据库远程权限 mysql -uroot -proot grant all privileges on formal.* to root@'192.168.3.40' identified by ...

  8. GIT学习笔记(5):变基

    GIT学习笔记(5):变基rebase 变基 引入变基 在Git中整合来自不同分支的修改主要有两种方法:merge以及rebase. 整合分支最容易的方法是merge,他会把两个分支的最新快照以及两者 ...

  9. Kattis - amsterdamdistance【数学】

    Kattis - amsterdamdistance[数学] 题意 给出两个点 算出从第一个点到第二个点的最短距离,只不过这里不是直角坐标系, 是雷达图 思路 因为内圈的圆的路径要比外圈的小,所以我们 ...

  10. html 基础 超链接

    ***设置超链接的样式示例  a:link 超链接被点前状态 a:visited 超链接点击后状态 a:hover 悬停在超链接时 a:active 点击超链接时 在定义这些状态时,有一个顺序l v ...