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();
}
}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦