集册 Java实例教程 创建并发送电子邮件

创建并发送电子邮件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

512
创建并发送电子邮件


//package com.nowjava;

import java.util.Properties;
/**
nowjava 提供 
**/

import javax.mail.Message;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;


public class Main {

    public static void main(String[] argv) throws Exception {

        String subject = "nowjava.com";

        String text = "nowjava.com";

        admin_email(subject, text);

    }


    public static void admin_email(String subject, String text) {
/**来 自 n o w j a v a . c o m - 时代Java**/

        // send mail

        Properties props = new Properties();

        Session session = Session.getDefaultInstance(props, null);


        try {

            Message msg = new MimeMessage(session);

            msg.setFrom(new InternetAddress(

                    "marcus.bueschleb@googlemail.com"));

            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(

                    
展开阅读全文