zoukankan      html  css  js  c++  java
  • java邮件

    package com.test.mail;
    
    import javax.mail.Message;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import java.util.Properties;
    
    /**
     * Created by Administrator on 14-9-17.
     */
    public class JaveMail {
        public static void main(String[] args) throws Exception {
            final String user = "lxb@goutrip.com";
            final String password = "Sand_Tiny@163.com";
    
            String fromAddress = "lxb@goutrip.com";
            String toAddress = "sand_tiny@163.com";
            String subject = "邮件测试主题";
            String content = "这是一个测试邮件<b>哈哈</b>";
    
            //配置参数
            Properties props = new Properties();
            props.setProperty("mail.smtp.auth", "true");
            props.setProperty("mail.transport.protocol", "smtp");
            props.setProperty("mail.host", "smtp.exmail.qq.com");
            // 方法一:使用transport对象发送邮件
            {
                //通过参数生成会话
                Session session = Session.getInstance(props);
                //启用调试模式
                session.setDebug(true);
                //创建一封邮件,并设置信息
                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress(fromAddress));
                message.setSubject(subject);
                message.setText(content);
                //创建传输
                Transport transport = session.getTransport();
                //连接smtp服务器
                transport.connect(user, password);
                //发送
                transport.sendMessage(message, new InternetAddress[]{new InternetAddress(toAddress)});
                transport.close();
            }
        }
    }
    
  • 相关阅读:
    podupdate时没有进度
    IOS开发
    ios事件传递
    ioshittest的用法
    Ios中时间无法响应
    OS开发(Objective-C)常用库索引
    IOS时间戳
    iOS- 详解文本属性Attributes
    IOSView显示特性设置
    Xcode的Architectures和Valid Architectures的区别,
  • 原文地址:https://www.cnblogs.com/sand-tiny/p/3977555.html
Copyright © 2011-2022 走看看