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"); } }
  • 相关阅读:
    [剑指offer] 赋值运算符重载
    [hihoCoder] 股票价格
    [LintCode] Kth Smallest Number in Sorted Matrix
    [LeetCode] Subarray Sum Equals K | 前缀和+哈希表
    [LeetCode] Add and Search Word
    [LeetCode] Implement Trie
    Tableau基础练习(三)
    Tableau基础练习(二)
    Tableau基础练习(一)
    SpringMVC用户请求下载文件
  • 原文地址:https://www.cnblogs.com/zhoushengbing/p/3251292.html
Copyright © 2011-2022 走看看