zoukankan      html  css  js  c++  java
  • 邮件发送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"); } }
  • 相关阅读:
    js交互数据
    js字符串操作
    js数组操作
    hasattr ,setarrt, getattr属性
    装饰器
    redis数据库安装
    ubuntu中mysql数据库安装与删除
    装换器
    jinjia2
    Laravel框架与ThinkPHP框架的不同
  • 原文地址:https://www.cnblogs.com/zhoushengbing/p/3251292.html
Copyright © 2011-2022 走看看