JavaMail

package com.tom;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class test2 {

/**
* @param args
* @throws EmailException
*/
public static void main(String[] args) throws EmailException {
SimpleEmail email = new SimpleEmail();

       //设置发送主机的服务器地址

       email.setHostName("smtp.sina.com");

       //设置收件人邮箱

       email.addTo("[email protected]");

       //发件人邮箱

       email.setFrom("[email protected]", "haha");

       //如果要求身份验证,设置用户名、密码,分别为发件人在邮件服务器上注册的用户名和密码

       email.setAuthentication("tjmzgn", "123456");

       //设置邮件的主题

       email.setSubject("Hello, This is My First Email Application");

       //邮件正文消息
      
       email.setMsg("tongjm javamail test");

       email.send();

       System.out.println("The SimpleEmail send sucessful!!!");

    }





}

你可能感兴趣的:(apache,qq)