继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

javamail发送邮件 发送代码参考

car
关注TA
已关注
手记 83
粉丝 56
获赞 363
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import junit.framework.TestCase;

public class JMail extends TestCase {
    public void testName() throws AddressException, MessagingException {

        Properties props = new Properties();
        props.setProperty("mail.smtp.auth", "true");
        props.setProperty("mail.transport.protocol", "smtp");
        Session session = Session.getInstance(props);
        session.setDebug(true);
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(""));
        msg.setText("this is the first mail by java programing!");
        msg.setSubject("SendMessageDemo1");
        Transport transport = session.getTransport();
        transport.connect("smtp.sina.com", 25, "", "");
        transport.sendMessage(msg, new Address[] { new InternetAddress("") });
        transport.close();
    }
}
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP