<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.sql.*,java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*"%>
<%
String qm ="vzgwjsznzunycbdj"; //鎮ㄧ殑QQ瀵嗙爜
String tu = "qq.com"; //浣犻偖绠辩殑鍚庣紑鍩熷悕
String tto="3451233113@qq.com"; //鎺ユ敹閭欢鐨勯偖绠?
String ttitle="鏁版嵁搴撳瘑鐮佷慨鏀规垚鍔熼€氱煡淇?鎿嶄綔浜篿p:";
String tcontent="鎮ㄧ殑瀵嗙爜宸茬粡琚慨鏀逛负:123456 璇峰垏璁? 鎿嶄綔浜篿p:127.0.0.1 ,濡備笉鏄偍鏈汉鎿嶄綔璇存槑鎮ㄧ殑瀵嗙爜宸茬粡娉勬紡,璇风珛鍗冲拰鎴戜滑鑱旂郴! ! ";
Properties props=new Properties();
props.put("mail.smtp.host","smtp."+tu);//鍙戜俊鐨勪富鏈猴紝杩欓噷鎴戝~鍐欑殑鏄垜浠叕鍙哥殑涓绘満锛佸彲浠ヤ笉鐢ㄤ慨鏀癸紒
props.put("mail.smtp.auth","true");
Session s=Session.getInstance(props);
s.setDebug(true);
MimeMessage message=new MimeMessage(s);
//缁欐秷鎭璞¤缃彂浠朵汉/鏀朵欢浜?涓婚/鍙戜俊鏃堕棿
InternetAddress from=new InternetAddress("536770346@"+tu); //杩欓噷鐨?15798090 鏀逛负鎮ㄥ彂淇$殑QQ鍙?
message.setFrom(from);
InternetAddress to=new InternetAddress(tto);
message.setRecipient(Message.RecipientType.TO,to);
message.setSubject(ttitle);
message.setSentDate(new Date());
//缁欐秷鎭璞¤缃唴瀹?
BodyPart mdp=new MimeBodyPart();//鏂板缓涓€涓瓨鏀句俊浠跺唴瀹圭殑BodyPart瀵硅薄
mdp.setContent(tcontent,"text/html;charset=gb2312");//缁橞odyPart瀵硅薄璁剧疆鍐呭鍜屾牸寮?缂栫爜鏂瑰紡
Multipart mm=new MimeMultipart();//鏂板缓涓€涓狹imeMultipart瀵硅薄鐢ㄦ潵瀛樻斁BodyPart瀵?
//璞?浜嬪疄涓婂彲浠ュ瓨鏀惧涓?
mm.addBodyPart(mdp);//灏咮odyPart鍔犲叆鍒癕imeMultipart瀵硅薄涓?鍙互鍔犲叆澶氫釜BodyPart)
message.setContent(mm);//鎶妋m浣滀负娑堟伅瀵硅薄鐨勫唴瀹?
message.saveChanges();
Transport transport=s.getTransport("smtp");
transport.connect("smtp.exmail."+tu,"536770346",qm); //杩欓噷鐨?15798090涔熻淇敼涓烘偍鐨凲Q鍙风爜
transport.sendMessage(message,message.getAllRecipients());
transport.close();
%>
鎻忚堪锛氬凡缁忓紑閫氫簡QQ閭鐨凷MTP鏈嶅姟锛屼篃鏄敤鐨勬渶鏂扮殑鎺堟潈鐮佺櫥闄嗭紝杩樻槸鏄剧ず浠ヤ笅鐨勯敊璇細
2016-5-30 15:21:53 org.apache.catalina.core.StandardWrapperValve invoke
涓ラ噸: Servlet.service() for servlet [jsp] in context with path [/jfree] threw exception [An exception occurred processing JSP page /index.jsp at line 36
33: message.setContent(mm);//鎶妋m浣滀负娑堟伅瀵硅薄鐨勫唴瀹?
34: message.saveChanges();
35: Transport transport=s.getTransport("smtp");
36: transport.connect("smtp.exmail."+tu,"536770346",qm); //杩欓噷鐨?15798090涔熻淇敼涓烘偍鐨凲Q鍙风爜
37: transport.sendMessage(message,message.getAllRecipients());
38: transport.close();
39: %>
Stacktrace:] with root cause
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:319)
at javax.mail.Service.connect(Service.java:169)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:103)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2476)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2465)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:619)
535 Error: 璇蜂娇鐢ㄦ巿鏉冪爜鐧诲綍銆傝鎯呰鐪? http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
15 涓В鍐虫柟妗?/h2>
#1
瑙e喅浜嗗悧 鎴戜篃閬囧埌浜?
#2
鎴戜篃閬囧埌浜嗭紝鎺堟潈鐮佸凡缁忓啓浜嗭紝鍙繕鏄湁闂
#3
鍚屾牱锛屾巿鏉冪爜宸茬粡鍐欎簡锛岃繕鏄湁闂
#4
娌′汉鐭ラ亾鍘熷洜鍚楋紵
#5
qq鐨勬湁涓€涓畨鍏ㄥ崗璁瀹炵幇ssl,杩欎釜涓嶅紕濂斤紝鏄病鐢ㄧ殑锛屾垜鐩存帴鎹?63 閭锛屽氨鍙互浜?
#6
163鍔ㄤ笉鍔ㄥ氨瑙嗕负鍨冨溇閭欢鎶?54SPM:DT,鎴戞墠鏉ュ紕QQ閭鐨?
#7
涓嶈繃鎴?63涔熸湁鍙戞垚鍔熺殑锛屽氨鏄笉绋冲畾
#8
鎴戞槸浠?63鍙戝埌qq涓嶈 浣嗘槸163鍙互鍙?63 鐨?nbsp; qq鍙戦兘鍙戜笉鍑烘潵鍟?nbsp;鏈夋巿鏉冪爜 杩樻槸娌$敤
#9
闂瑙e喅浜嗗悧锛熸垜163閭琚綋鍨冨溇閭欢澶勭悊锛孮Q瑕佹巿鏉冪爜鐧讳笉涓婂幓
#10
閬囧埌鐨勯棶棰?nbsp; 鍚?妤硷紝绔熺劧娌℃湁澶х瑙e喅銆傘€傘€傘€傘€?
#11
鎸栦釜鍧燂紝浠婂ぉ涔熼亣鍒板悓鏍风殑闂浜嗭紝鏈€鍚庤В鍐充簡锛岀粰鍚庢潵鑰呬竴浜涜В鍐虫柟妗?
鎺堟潈鐮佽幏鍙栭棶棰樿В鍐冲弬鑰冨涓嬶細
http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
SSL闂浠ュ強 failed to connect, no password specified?闂瑙e喅鍙傝€冨涓嬶細
http://www.cnblogs.com/15ho/p/5891148.html
鎴戠殑浠g爜濡備笅锛堟敞鎰忓紩鍏ail.jar鍖咃級锛?
import com.sun.net.ssl.internal.ssl.Provider;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.security.Security;
import java.util.Date;
import java.util.Properties;
public class MailSender {
private static MimeMessage message;
public static void main(String[] args) throws MessagingException {
Security.addProvider(new Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
//QQ閭鏈嶅姟鍣?
String smtpHost="smtp.qq.com";
//閭鐢ㄦ埛鍚嶏紝鍗砆Q璐﹀彿
final String username = "QQ璐﹀彿";
//閭鎺堟潈鐮?
final String password = "鎺堟潈鐮?;
//瑕佸彂閫佸埌鐨勯偖绠?
String to = "to@qq.com";
//鑷繁鐨勯偖绠?
String from = "from@qq.com";
Transport transport;
Properties props = new Properties();
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.setProperty("mail.smtp.auth", "true");
props.put("mail.smtp.host",smtpHost);
props.put("mail.smtp.username", username);
props.put("mail.smtp.password", password);
Session session = Session.getDefaultInstance(props, new Authenticator() {
//韬唤璁よ瘉
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
InternetAddress[] addresses = {new InternetAddress(to)};
message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,addresses);
message.setSubject("Hello");
message.setSentDate(new Date());
message.setText("hello, How are you");
transport = session.getTransport("smtp");
transport.connect(smtpHost, username, password);
transport.send(message);
System.out.println("email has been sent");
}
}
#12
11妤兼瑙e晩锛屾姌纾ㄥ崐澶╃粓浜庡彲浠ユ垚鍔熷彂閫佸暒锛佸璋紒
#13
澶氫簭澶т浆鎸栧潫锛?
#14
#15
杩欏氨鍙互浜?
#1
瑙e喅浜嗗悧 鎴戜篃閬囧埌浜?
#2
鎴戜篃閬囧埌浜嗭紝鎺堟潈鐮佸凡缁忓啓浜嗭紝鍙繕鏄湁闂
#3
鍚屾牱锛屾巿鏉冪爜宸茬粡鍐欎簡锛岃繕鏄湁闂
#4
娌′汉鐭ラ亾鍘熷洜鍚楋紵
#5
qq鐨勬湁涓€涓畨鍏ㄥ崗璁瀹炵幇ssl,杩欎釜涓嶅紕濂斤紝鏄病鐢ㄧ殑锛屾垜鐩存帴鎹?63 閭锛屽氨鍙互浜?
#6
163鍔ㄤ笉鍔ㄥ氨瑙嗕负鍨冨溇閭欢鎶?54SPM:DT,鎴戞墠鏉ュ紕QQ閭鐨?
#7
涓嶈繃鎴?63涔熸湁鍙戞垚鍔熺殑锛屽氨鏄笉绋冲畾
#8
鎴戞槸浠?63鍙戝埌qq涓嶈 浣嗘槸163鍙互鍙?63 鐨?nbsp; qq鍙戦兘鍙戜笉鍑烘潵鍟?nbsp;鏈夋巿鏉冪爜 杩樻槸娌$敤
#9
闂瑙e喅浜嗗悧锛熸垜163閭琚綋鍨冨溇閭欢澶勭悊锛孮Q瑕佹巿鏉冪爜鐧讳笉涓婂幓
#10
閬囧埌鐨勯棶棰?nbsp; 鍚?妤硷紝绔熺劧娌℃湁澶х瑙e喅銆傘€傘€傘€傘€?
#11
鎸栦釜鍧燂紝浠婂ぉ涔熼亣鍒板悓鏍风殑闂浜嗭紝鏈€鍚庤В鍐充簡锛岀粰鍚庢潵鑰呬竴浜涜В鍐虫柟妗?
鎺堟潈鐮佽幏鍙栭棶棰樿В鍐冲弬鑰冨涓嬶細
http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
SSL闂浠ュ強 failed to connect, no password specified?闂瑙e喅鍙傝€冨涓嬶細
http://www.cnblogs.com/15ho/p/5891148.html
鎴戠殑浠g爜濡備笅锛堟敞鎰忓紩鍏ail.jar鍖咃級锛?
import com.sun.net.ssl.internal.ssl.Provider;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.security.Security;
import java.util.Date;
import java.util.Properties;
public class MailSender {
private static MimeMessage message;
public static void main(String[] args) throws MessagingException {
Security.addProvider(new Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
//QQ閭鏈嶅姟鍣?
String smtpHost="smtp.qq.com";
//閭鐢ㄦ埛鍚嶏紝鍗砆Q璐﹀彿
final String username = "QQ璐﹀彿";
//閭鎺堟潈鐮?
final String password = "鎺堟潈鐮?;
//瑕佸彂閫佸埌鐨勯偖绠?
String to = "to@qq.com";
//鑷繁鐨勯偖绠?
String from = "from@qq.com";
Transport transport;
Properties props = new Properties();
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.setProperty("mail.smtp.auth", "true");
props.put("mail.smtp.host",smtpHost);
props.put("mail.smtp.username", username);
props.put("mail.smtp.password", password);
Session session = Session.getDefaultInstance(props, new Authenticator() {
//韬唤璁よ瘉
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
InternetAddress[] addresses = {new InternetAddress(to)};
message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,addresses);
message.setSubject("Hello");
message.setSentDate(new Date());
message.setText("hello, How are you");
transport = session.getTransport("smtp");
transport.connect(smtpHost, username, password);
transport.send(message);
System.out.println("email has been sent");
}
}
鎺堟潈鐮佽幏鍙栭棶棰樿В鍐冲弬鑰冨涓嬶細
http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
SSL闂浠ュ強 failed to connect, no password specified?闂瑙e喅鍙傝€冨涓嬶細
http://www.cnblogs.com/15ho/p/5891148.html
鎴戠殑浠g爜濡備笅锛堟敞鎰忓紩鍏ail.jar鍖咃級锛?
import com.sun.net.ssl.internal.ssl.Provider;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.security.Security;
import java.util.Date;
import java.util.Properties;
public class MailSender {
private static MimeMessage message;
public static void main(String[] args) throws MessagingException {
Security.addProvider(new Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
//QQ閭鏈嶅姟鍣?
String smtpHost="smtp.qq.com";
//閭鐢ㄦ埛鍚嶏紝鍗砆Q璐﹀彿
final String username = "QQ璐﹀彿";
//閭鎺堟潈鐮?
final String password = "鎺堟潈鐮?;
//瑕佸彂閫佸埌鐨勯偖绠?
String to = "to@qq.com";
//鑷繁鐨勯偖绠?
String from = "from@qq.com";
Transport transport;
Properties props = new Properties();
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.setProperty("mail.smtp.auth", "true");
props.put("mail.smtp.host",smtpHost);
props.put("mail.smtp.username", username);
props.put("mail.smtp.password", password);
Session session = Session.getDefaultInstance(props, new Authenticator() {
//韬唤璁よ瘉
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
InternetAddress[] addresses = {new InternetAddress(to)};
message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,addresses);
message.setSubject("Hello");
message.setSentDate(new Date());
message.setText("hello, How are you");
transport = session.getTransport("smtp");
transport.connect(smtpHost, username, password);
transport.send(message);
System.out.println("email has been sent");
}
}
#12
11妤兼瑙e晩锛屾姌纾ㄥ崐澶╃粓浜庡彲浠ユ垚鍔熷彂閫佸暒锛佸璋紒
#13
澶氫簭澶т浆鎸栧潫锛?
#14
#15
杩欏氨鍙互浜?
#1
瑙e喅浜嗗悧 鎴戜篃閬囧埌浜?
#2
鎴戜篃閬囧埌浜嗭紝鎺堟潈鐮佸凡缁忓啓浜嗭紝鍙繕鏄湁闂
#3
鍚屾牱锛屾巿鏉冪爜宸茬粡鍐欎簡锛岃繕鏄湁闂
#4
娌′汉鐭ラ亾鍘熷洜鍚楋紵
#5
qq鐨勬湁涓€涓畨鍏ㄥ崗璁瀹炵幇ssl,杩欎釜涓嶅紕濂斤紝鏄病鐢ㄧ殑锛屾垜鐩存帴鎹?63 閭锛屽氨鍙互浜?
#6
163鍔ㄤ笉鍔ㄥ氨瑙嗕负鍨冨溇閭欢鎶?54SPM:DT,鎴戞墠鏉ュ紕QQ閭鐨?
#7
涓嶈繃鎴?63涔熸湁鍙戞垚鍔熺殑锛屽氨鏄笉绋冲畾
#8
鎴戞槸浠?63鍙戝埌qq涓嶈 浣嗘槸163鍙互鍙?63 鐨?nbsp; qq鍙戦兘鍙戜笉鍑烘潵鍟?nbsp;鏈夋巿鏉冪爜 杩樻槸娌$敤
#9
闂瑙e喅浜嗗悧锛熸垜163閭琚綋鍨冨溇閭欢澶勭悊锛孮Q瑕佹巿鏉冪爜鐧讳笉涓婂幓
#10
閬囧埌鐨勯棶棰?nbsp; 鍚?妤硷紝绔熺劧娌℃湁澶х瑙e喅銆傘€傘€傘€傘€?
#11
鎸栦釜鍧燂紝浠婂ぉ涔熼亣鍒板悓鏍风殑闂浜嗭紝鏈€鍚庤В鍐充簡锛岀粰鍚庢潵鑰呬竴浜涜В鍐虫柟妗?
鎺堟潈鐮佽幏鍙栭棶棰樿В鍐冲弬鑰冨涓嬶細
http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
SSL闂浠ュ強 failed to connect, no password specified?闂瑙e喅鍙傝€冨涓嬶細
http://www.cnblogs.com/15ho/p/5891148.html
鎴戠殑浠g爜濡備笅锛堟敞鎰忓紩鍏ail.jar鍖咃級锛?
import com.sun.net.ssl.internal.ssl.Provider;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.security.Security;
import java.util.Date;
import java.util.Properties;
public class MailSender {
private static MimeMessage message;
public static void main(String[] args) throws MessagingException {
Security.addProvider(new Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
//QQ閭鏈嶅姟鍣?
String smtpHost="smtp.qq.com";
//閭鐢ㄦ埛鍚嶏紝鍗砆Q璐﹀彿
final String username = "QQ璐﹀彿";
//閭鎺堟潈鐮?
final String password = "鎺堟潈鐮?;
//瑕佸彂閫佸埌鐨勯偖绠?
String to = "to@qq.com";
//鑷繁鐨勯偖绠?
String from = "from@qq.com";
Transport transport;
Properties props = new Properties();
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.setProperty("mail.smtp.auth", "true");
props.put("mail.smtp.host",smtpHost);
props.put("mail.smtp.username", username);
props.put("mail.smtp.password", password);
Session session = Session.getDefaultInstance(props, new Authenticator() {
//韬唤璁よ瘉
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
InternetAddress[] addresses = {new InternetAddress(to)};
message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,addresses);
message.setSubject("Hello");
message.setSentDate(new Date());
message.setText("hello, How are you");
transport = session.getTransport("smtp");
transport.connect(smtpHost, username, password);
transport.send(message);
System.out.println("email has been sent");
}
}
鎺堟潈鐮佽幏鍙栭棶棰樿В鍐冲弬鑰冨涓嬶細
http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
SSL闂浠ュ強 failed to connect, no password specified?闂瑙e喅鍙傝€冨涓嬶細
http://www.cnblogs.com/15ho/p/5891148.html
鎴戠殑浠g爜濡備笅锛堟敞鎰忓紩鍏ail.jar鍖咃級锛?
import com.sun.net.ssl.internal.ssl.Provider;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.security.Security;
import java.util.Date;
import java.util.Properties;
public class MailSender {
private static MimeMessage message;
public static void main(String[] args) throws MessagingException {
Security.addProvider(new Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
//QQ閭鏈嶅姟鍣?
String smtpHost="smtp.qq.com";
//閭鐢ㄦ埛鍚嶏紝鍗砆Q璐﹀彿
final String username = "QQ璐﹀彿";
//閭鎺堟潈鐮?
final String password = "鎺堟潈鐮?;
//瑕佸彂閫佸埌鐨勯偖绠?
String to = "to@qq.com";
//鑷繁鐨勯偖绠?
String from = "from@qq.com";
Transport transport;
Properties props = new Properties();
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.setProperty("mail.smtp.auth", "true");
props.put("mail.smtp.host",smtpHost);
props.put("mail.smtp.username", username);
props.put("mail.smtp.password", password);
Session session = Session.getDefaultInstance(props, new Authenticator() {
//韬唤璁よ瘉
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
InternetAddress[] addresses = {new InternetAddress(to)};
message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,addresses);
message.setSubject("Hello");
message.setSentDate(new Date());
message.setText("hello, How are you");
transport = session.getTransport("smtp");
transport.connect(smtpHost, username, password);
transport.send(message);
System.out.println("email has been sent");
}
}
#12
11妤兼瑙e晩锛屾姌纾ㄥ崐澶╃粓浜庡彲浠ユ垚鍔熷彂閫佸暒锛佸璋紒
#13
澶氫簭澶т浆鎸栧潫锛?
#14
#15
杩欏氨鍙互浜?