javaMail邮件发送问题

帅的不像实力派 发布于 2016/12/04 14:21
阅读 233
收藏 0

自己动手写了的一个关于javaMail的实例,但是一直提示

Exception in thread "main" javax.mail.NoSuchProviderException: No provider for value
at javax.mail.Session.getProvider(Session.java:455)
at javax.mail.Session.getTransport(Session.java:650)
at javax.mail.Session.getTransport(Session.java:631)
at javax.mail.Session.getTransport(Session.java:617)
at com.etoak.test.TestMail.main(TestMail.java:33)
,百度看了这个类是有的,引入的并没有错。


下面贴一下代码:

package com.etoak.test;


import java.util.Date;
import java.util.Properties;


import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class TestMail {


/**
* 发件人的邮箱和密码
* @param args
*/
private static String myEmailAccount = "72653124@qq.com";
private static String myEmailPassword = "ratl kgoh tauh bbjd";
private static String myEmialHost = "smtp.qq.com";
private static String receiver = "wttt1234@yeah.net";
public static void main(String[] args) throws Exception {
//1.创建参数配置
Properties prop = new Properties();
prop.setProperty("mail.transport.protocol","value");
prop.setProperty("mail.host", myEmialHost);
prop.setProperty("mail.smtp.auth","true");

//2.根据配置创建会话,用于和邮件服务器交互
Session session = Session.getDefaultInstance(prop);
session.setDebug(true);
MimeMessage message = createMimeMessage(session,myEmailAccount,receiver);//创建一封邮件
Transport transport = session.getTransport();
transport.connect(myEmailAccount,myEmailPassword);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}


/**
* 创建一份简单邮件
*/
public static MimeMessage createMimeMessage(Session session,String sendMail,String receiveMail) throws Exception{
MimeMessage  message = new MimeMessage (session);
message.setFrom(new InternetAddress(sendMail,"某宝王","UTF-8"));
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail,"XX用户","UTF-8"));
message.setSubject("年终大庆","UTF-8");
message.setContent("XX用户你好,今天全场五折起","text/html;charset=UTF-8");
message.setSentDate(new Date());;
message.saveChanges();
return message;
}

}

加载中
返回顶部
顶部