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. shell function/for in/for (())/string concat/has dir/rename using regex/if(())/exit/execute command and pass value to variable/execute python

    #!/bin/bash #remove the MER.*_ in file name for all the files in a dir function getdir(){ for elemen ...

  2. 替换DOM元素 parent.replaceChild(new, old)

    p.replaceChild(nodeNext, p.children[j]); p.replaceChild(nodePrev, p.children[j + 1]);

  3. Python(数据库之约束表的关系)

    一.约束 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性 主要分为: RIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FOREIGN KEY ...

  4. weal woe

    He is worth no weal that can bide no woe. 禁不起吃苦的人不配得到幸福 有句谚语叫No weal without woe 福兮祸所伏 ; 祸兮福所倚 weal和 ...

  5. alter session set events

    .alter session set events 一.Oracle跟踪文件    Oracle跟踪文件分为三种类型,一种是后台报警日志文件,记录数据库在启动.关闭和运行期间后台进程的活动情况,如表空 ...

  6. php RFC兼容的电子邮件地址验证

    php中,进行RFC兼容的电子邮件地址验证的方法,有需要的朋友参考下吧. 分享一个可以验证RFC兼容的电子邮件地址的代码,支持RFC1123,2396,3696,4291,4343,5321等的验证. ...

  7. oracle ORA-01704: string literal too long

    导出数据时,在SQL拼接处,提示 oracle ORA-01704: string literal too long sql:  WITH already_in AS (SELECT distinct ...

  8. 子元素绝对定位absolute后,自动撑开宽度

    position: absolute;   white-space: nowrap;

  9. MAC 终端颜色设置

    在bash中,可以通过更改PS1环境变量的值来设置提示行.通常的提示符颜色单调,用户可以通过在PS1中添加颜色代码序列来设置提示符中不同信息以不同颜色显示. 添加颜色相当容易:第一步是设计不带颜色的提 ...

  10. 5. Longest Palindromic Substring(最长回文子串 manacher 算法/ DP动态规划)

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...