• 邮件发送2


    package com.tarena.netctoss.test;
    import java.util.Date;
    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;
    public class MailTest {
    	public static boolean send(String to,String subject,String content){
    		//第一步:创建session
    		Properties pros=new Properties();
    		//指定邮件的传输协议
    		pros.put("mail.smtp.host",  "smtp.163.com");
            pros.put("mail.smtp.auth", "true");
            
    		Session session=Session.getDefaultInstance(pros);
    		
    		session.setDebug(true);
    		try{
    			Transport transport = session.getTransport("smtp");
    			transport.connect("smtp.163.com","snail_zhou","***************");//服务器,邮箱号(不要后面的@163.com),邮箱的密码
    			MimeMessage message=new MimeMessage(session);
    message.setSubject(subject);//设置主题 message.setContent(content,"text/html;charset=utf-8");//设置内容 message.setSentDate(new Date());//发送日期 message.setFrom(new InternetAddress("snail_zhou@163.com"));//发件人邮箱 transport.sendMessage(message, InternetAddress.parse(to));//发送 return true; }catch(Exception e){ e.printStackTrace(); } return false; } public static void main(String[] args) { MailTest.send("972661036@qq.com", "验证码", "123456"); } }
  • 相关阅读:
    Eclipse配置Maven详细教程
    Spring MVC 搭建web项目示例
    C# Action 和Func
    C# params 用法简介
    WPF绘图性能问题
    C# EventWaitHandle用法
    C#5.0 异步编程async/await用法
    通过Struts2Web应用框架深入理解MVC
    Java过滤器—Filter用法简介
    WPF内嵌CEF控件,与JS交互
  • 原文地址:https://www.cnblogs.com/zhoushengbing/p/3251292.html
Copyright © 2020-2023  润新知